zsh-users
 help / color / mirror / code / Atom feed
From: Elliott Cable <me@ell.io>
To: zsh-users@zsh.org
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	[thread overview]
Message-ID: <AANLkTikFsJGitoiU49kJphErOsxbCN_BrerNcaHcb2kR@mail.gmail.com> (raw)

(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)


             reply	other threads:[~2011-02-11  6:04 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-11  6:03 Elliott Cable [this message]
2011-02-11 16:26 ` Bart Schaefer

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=AANLkTikFsJGitoiU49kJphErOsxbCN_BrerNcaHcb2kR@mail.gmail.com \
    --to=me@ell.io \
    --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).