Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: How can I maintain my last command’s exit-status while resetting my prompt in ZSH?
On Thu, Feb 10, 2011 at 10:03 PM, Elliott Cable <me@xxxxxx> wrote:
>
> The problem: When the keymap changes (that is, when I toggle through
> the “command” and “insert” modes using, as an example, `a` and then
> the escape key, the `$?` exit-status is overtrodden with a successful
> `0` status, thus causing the prompt to display in green instead of red
> (even if the previous command failed). How can I save or set the
> prompt such that the `%(?|…|…)` portions of `$PS1` will properly
> display the exit status of the *last command sent to the shell*?
This was fixed in July 2010, so eventually you won't need to do anything:
* users/15217: Src/Zle/zle_main.c: use top-level status
when redrawing prompt.
In the meantime, try this:
function zle-keymap-select {
local Q=$?
psvar[1]="${${KEYMAP/(main|viins)/>}/vicmd/}"
(return $Q)
zle reset-prompt
psvar[1]=""
}
If your zsh is recent enough to have anonymous functions, you can replace
the subshell (return $Q) with (){ return $Q }.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author