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 12479 invoked from network); 20 Jun 2020 11:07:25 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 20 Jun 2020 11:07:25 -0000 Received: (qmail 3339 invoked by alias); 20 Jun 2020 11:07:14 -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: 24938 Received: (qmail 9459 invoked by uid 1010); 20 Jun 2020 11:07:14 -0000 X-Qmail-Scanner-Diagnostics: from out4-smtp.messagingengine.com 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(66.111.4.28):SA:0(-2.6/5.0):. Processed in 4.069109 secs); 20 Jun 2020 11:07:14 -0000 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedrudejkedgfeeiucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpeffhffvuffkjghfofggtgfgsehtqh dttdertdejnecuhfhrohhmpeffrghnihgvlhcuufhhrghhrghfuceougdrshesuggrnhhi vghlrdhshhgrhhgrfhdrnhgrmhgvqeenucggtffrrghtthgvrhhnpefhtdetfeehveeutd ehuddtieefgeettedtjedtffehudeiieejleetteekudetheenucfkphepjeelrddujeei rdefledrieelnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrh homhepugdrshesuggrnhhivghlrdhshhgrhhgrfhdrnhgrmhgv X-ME-Proxy: Date: Sat, 20 Jun 2020 11:06:29 +0000 From: Daniel Shahaf To: Sebastian Stark Cc: zsh-users@zsh.org Subject: Re: Dynamic parameters for PROMPT_SUBST functions Message-ID: <20200620110629.3a7f26ab@tarpaulin.shahaf.local2> In-Reply-To: <20200619170847.iq2bjrnrmon5cctd@singold> References: <20200619063233.zybs27xvqp56t4p5@singold> <20200619105640.17bd3107@tarpaulin.shahaf.local2> <20200619170847.iq2bjrnrmon5cctd@singold> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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: =20 > >> I am trying to have a function call in my prompt that gets the return > >> value of the last command as a parameter (%?). =20 > > > >What would you do with =C2=AB%?=C2=BB if you could get its value? =20 >=20 > I would try to split it into signal and return value information, so I=20 > do not get "130" if I ctrl-c, but something like 0 and INT. That information isn't available via %?: . % PS1=3D'%?%# ' 0% perl -E 'kill 9, $$'=20 zsh: killed perl -E 'kill 9, $$' 137% perl -E 'exit (9 + 128)'=20 137%=20 Note how %? expanded to the same value in both cases. The information is not available via $pipestatus either. However, the "killed" (or "interrupted", etc) message is only printed when a job exited with a signal. Furthermore, if you don't care about programs whose exit codes just happen to be in the 128+signal range, you can do: . % setopt promptsubst % PS1=3D'$signals[1 + ($? - 128)]%# ' % (exit 137) zsh: exit 137 ( exit 137; ) KILL%=20 The variable =C2=AB$signals=C2=BB is predefined. Just make sure that $? is= the right value. (If you have other $(=E2=80=A6) in there, they might overwrite =C2=AB$?=C2=BB? I haven't tested.) And to show the numeric exit code when there isn't a signal associated, using the ternary condition syntax: . PS1=3D'${signals[1 + ($? - 128)]:-"%(?..%?)"}%# ' This does not handle the case that ${signals[=E2=80=A6]} is EXIT, ZERR, or = DEBUG. Cheers, Daniel