zsh-users
 help / color / mirror / code / Atom feed
From: Christopher Nebel <c.nebel@apple.com>
To: zsh-users <zsh-users@zsh.org>
Subject: Processing "%?" in PROMPT?
Date: Wed, 20 Nov 2019 13:27:32 -0800	[thread overview]
Message-ID: <2879A761-D4D3-44C5-8D54-D58D9E3F5EBF@apple.com> (raw)

In my PROMPT, I want to get the status of the last command executed before the prompt, what in prompt expansion would be %?, but I want to pass it to a function.  (Why?  I like the idea of %? in the prompt, but thought it would be nice to dress it up a bit by rendering it as something other than just a number: “EX_USAGE” instead of “64” or “SIGILL” instead of “132”.  That means passing the value of %? to a function to generate the text that appears in the prompt.)

My first attempt was to set PROMPT to ‘$(pretty-status %?)’, which doesn’t work because the “%?” is passed literally.  I’ve tried various ways of evaluating “%?” — “print -P %?”, the “(%)” expansion flag — but none them work, because they expand to the same thing as “$?”, which is the status of the last command executed anywhere, including inside command substitution for the prompt.  I could use a precmd function to save $? in a global, but only if I could guarantee that it was called before anything else, and that’s not a promise I’m comfortable making.

Any suggestions?  zsh clearly has the value I want, since it uses it in prompt percent expansion, but how do I get at it?  I’m honestly not sure if the behavior I’m seeing in “print -P %?” is a bug or if it’s working as designed.  I’m mostly using zsh 5.3, but I’m seeing the same thing in 5.9.


—Chris N.

             reply	other threads:[~2019-11-20 21:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-20 21:27 Christopher Nebel [this message]
2019-11-20 21:42 ` Roman Perepelitsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2879A761-D4D3-44C5-8D54-D58D9E3F5EBF@apple.com \
    --to=c.nebel@apple.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).