Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
How can I maintain my last command’s exit-status while resetting my prompt in ZSH?
- X-seq: zsh-users 15793
- From: Elliott Cable <me@xxxxxx>
- To: zsh-users@xxxxxxx
- Subject: How can I maintain my last command’s exit-status while resetting my prompt in ZSH?
- Date: Fri, 11 Feb 2011 01:03:38 -0500
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
(I’m really not a mailing-list kinda guy, usually Google/IRC/Twitter
and such for help, but I’ve hit dead-ends everywhere I’ve gone with
this. Forgive me if I make some sort of major mailing-list faux-pas!)
I’m trying to make an über-simple (single-character) prompt that gives
me as much information as possible. Here’s what I have at the moment
(had it for ages, can’t remember where I found the original):
# RPS1="['%1v', '%2v', '%3v', '%4v', '%5v', '%6v', '%7v', '%8v',
'%9v']" # debug
PS1=" %(?|%2F|%1F)%1(V|%1v|%(#|#|:))%(?|%2f|%1f) "
function zle-line-init {
zle -K vicmd
}
zle -N zle-line-init
function zle-keymap-select {
psvar[1]="${${KEYMAP/(main|viins)/>}/vicmd/}"
zle reset-prompt
psvar[1]=""
}
zle -N zle-keymap-select
This is fairly simple; it initializes the prompt into command mode on
rendering, and displays a `:` prompt when in the vi’s “command” mode,
and a `>` prompt (by changing `psvar[1]`) when in vi’s “insert” mode.
In addition, the `:` is replaced with `#` if you are acting as root,
and the color of the character exhibits the exit status of the last
command.
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*?
(I also posted this to Stack Overflow, but I don’t expect to see very
much ZSH expertise there… it seems to be primarily popular with Java
and C# developers:
http://stackoverflow.com/questions/4965994/how-can-i-maintain-my-last-commands-exit-status-while-resetting-my-prompt-in-zsh)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author