From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 21733 invoked from network); 21 Jun 2020 15:18:46 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 21 Jun 2020 15:18:46 -0000 Received: (qmail 25145 invoked by alias); 21 Jun 2020 15:18:34 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: List-Unsubscribe: Sender: zsh-users@zsh.org X-Seq: 24939 Received: (qmail 22058 invoked by uid 1010); 21 Jun 2020 15:18:34 -0000 X-Qmail-Scanner-Diagnostics: from mout-p-102.mailbox.org by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25842. spamassassin: 3.4.4. Clear:RC:0(80.241.56.152):SA:0(-2.7/5.0):. Processed in 3.064095 secs); 21 Jun 2020 15:18:34 -0000 X-Envelope-From: sstark+zsh@mailbox.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at mailbox.org designates 80.241.56.152 as permitted sender) X-Virus-Scanned: amavisd-new at heinlein-support.de Date: Sun, 21 Jun 2020 17:17:47 +0200 From: Sebastian Stark To: Daniel Shahaf Cc: zsh-users@zsh.org Subject: Re: Dynamic parameters for PROMPT_SUBST functions Message-ID: <20200621151747.xwfphcn5yia3oncj@singold> Mail-Followup-To: Daniel Shahaf , zsh-users@zsh.org References: <20200619063233.zybs27xvqp56t4p5@singold> <20200619105640.17bd3107@tarpaulin.shahaf.local2> <20200619170847.iq2bjrnrmon5cctd@singold> <20200620110629.3a7f26ab@tarpaulin.shahaf.local2> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200620110629.3a7f26ab@tarpaulin.shahaf.local2> X-MBO-SPAM-Probability: 0 X-Rspamd-Score: -2.91 / 15.00 / 15.00 X-Rspamd-Queue-Id: C1C08176F X-Rspamd-UID: 6013bd Am Samstag, den 20. Juni 2020 um 13:06 schrieb Daniel Shahaf: >Sebastian Stark wrote on Fri, 19 Jun 2020 19:08 +0200: >> Am Freitag, den 19. Juni 2020 um 13:04 schrieb Daniel Shahaf: >> >Sebastian Stark wrote on Fri, 19 Jun 2020 08:32 +0200: >> >> I am trying to have a function call in my prompt that gets the return >> >> value of the last command as a parameter (%?). >> > >> >What would you do with «%?» if you could get its value? >> >> I would try to split it into signal and return value information, so I >> do not get "130" if I ctrl-c, but something like 0 and INT. > >That information isn't available via %?: >. > % PS1='%?%# ' > 0% perl -E 'kill 9, $$' > zsh: killed perl -E 'kill 9, $$' > 137% perl -E 'exit (9 + 128)' > 137% > >Note how %? expanded to the same value in both cases. Yes, I noticed that this is not entirely clean. > % setopt promptsubst > % PS1='$signals[1 + ($? - 128)]%# ' > % (exit 137) > zsh: exit 137 ( exit 137; ) > KILL% > >The variable «$signals» is predefined. Just make sure that $? is the >right value. (If you have other $(…) in there, they might overwrite >«$?»? I haven't tested.) Thanks for this, I didn't know about the signals array. Also, your solution looks pretty much like what I was looking for. However, in my prompt variable this expands to the number, not the signal name. Your code does the right thing when used as PS1 without anything else, but not in combination with my other things in there. For now I will put that on my pile of unfinished things, as it seems to be complicated for little outcome. Thanks again! Sebastian