From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8350 invoked by alias); 11 Feb 2011 16:26:33 -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: 15796 Received: (qmail 18657 invoked from network); 11 Feb 2011 16:26:22 -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 brasslantern.com does not designate permitted sender hosts) MIME-Version: 1.0 In-Reply-To: References: Date: Fri, 11 Feb 2011 08:26:13 -0800 Message-ID: Subject: =?windows-1252?Q?Re=3A_How_can_I_maintain_my_last_command=92s_exit=2Dstat?= =?windows-1252?Q?us_while_resetting_my_prompt_in_ZSH=3F?= From: Bart Schaefer To: Elliott Cable Cc: zsh-users@zsh.org Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable On Thu, Feb 10, 2011 at 10:03 PM, Elliott Cable wrote: > > The problem: When the keymap changes (that is, when I toggle through > the =93command=94 and =93insert=94 modes using, as an example, `a` and th= en > 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 `%(?|=85|=85)` 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=3D$? psvar[1]=3D"${${KEYMAP/(main|viins)/>}/vicmd/}" (return $Q) zle reset-prompt psvar[1]=3D"" } If your zsh is recent enough to have anonymous functions, you can replace the subshell (return $Q) with (){ return $Q }.