From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 133 invoked by alias); 11 Feb 2011 06:04:01 -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: X-Seq: 15793 Received: (qmail 12186 invoked from network); 11 Feb 2011 06:03:59 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.1 Received-SPF: none (ns1.primenet.com.au: domain at ell.io does not designate permitted sender hosts) MIME-Version: 1.0 X-Originating-IP: [66.56.234.250] From: Elliott Cable Date: Fri, 11 Feb 2011 01:03:38 -0500 Message-ID: Subject: =?UTF-8?Q?How_can_I_maintain_my_last_command=E2=80=99s_exit=2Dstatus_w?= =?UTF-8?Q?hile_resetting_my_prompt_in_ZSH=3F?= To: zsh-users@zsh.org Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable (I=E2=80=99m really not a mailing-list kinda guy, usually Google/IRC/Twitte= r and such for help, but I=E2=80=99ve hit dead-ends everywhere I=E2=80=99ve g= one with this. Forgive me if I make some sort of major mailing-list faux-pas!) I=E2=80=99m trying to make an =C3=BCber-simple (single-character) prompt th= at gives me as much information as possible. Here=E2=80=99s what I have at the momen= t (had it for ages, can=E2=80=99t remember where I found the original): # RPS1=3D"['%1v', '%2v', '%3v', '%4v', '%5v', '%6v', '%7v', '%8v', '%9v']" # debug PS1=3D" %(?|%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]=3D"${${KEYMAP/(main|viins)/>}/vicmd/}" zle reset-prompt psvar[1]=3D"" } 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=E2=80=99s =E2=80=9Ccomm= and=E2=80=9D mode, and a `>` prompt (by changing `psvar[1]`) when in vi=E2=80=99s =E2=80=9Cins= ert=E2=80=9D 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 =E2=80=9Ccommand=E2=80=9D and =E2=80=9Cinsert=E2=80=9D 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 `%(?|=E2=80=A6|=E2=80=A6)` portions of `$PS1` will pro= perly display the exit status of the *last command sent to the shell*? (I also posted this to Stack Overflow, but I don=E2=80=99t expect to see ve= ry much ZSH expertise there=E2=80=A6 it seems to be primarily popular with Jav= a and C# developers: http://stackoverflow.com/questions/4965994/how-can-i-maintain-my-last-comma= nds-exit-status-while-resetting-my-prompt-in-zsh)