From 02efc2028bc26a550d3b01adfab2c03dbf3bcf2e Mon Sep 17 00:00:00 2001 From: Iain Patterson Date: Wed, 18 Nov 2009 15:46:57 +0000 Subject: [PATCH] Fix missing exit code in prompt. The exit code from the last command was not being shown when the command failed. This was a bug introduced by the fixing of escape sequences for iTerm. --- .profile.d/ps1.bashrc | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.profile.d/ps1.bashrc b/.profile.d/ps1.bashrc index cf6f1e6..87a2f1b 100644 --- a/.profile.d/ps1.bashrc +++ b/.profile.d/ps1.bashrc @@ -73,21 +73,28 @@ function __ps1() { # Default __ps1_user to 1. [ -z "$__ps1_user" ] && __ps1_user=1 - export PS1='$(__ps1_user $? \u@)\[\033[$(__ps1_col $? 2>/dev/null)m\]$(__ps1_user $? \h)\[\033[$(__ps1_colour_escape $GIT_COLOUR)m\]$(__ps1_git $? 2>/dev/null)\[\033[0m\]\[\033[$(__ps1_colour_escape $P4_COLOUR)m\]$(__ps1_p4 $? 2>/dev/null)\[\033[0m\]\[\033[$(__ps1_colour_escape $SVN_COLOUR)m\]$(__ps1_svn $? 2>/dev/null)\[\033[0m\]$(__ps1_ret $? 2>/dev/null):\w\$ ' + export PS1='$(__ps1_user $? \u@)\[\033[$(__ps1_col $? 2>/dev/null)m\]$(__ps1_user $? \h)\[\033[$(__ps1_colour_escape $? $GIT_COLOUR)m\]$(__ps1_git $? 2>/dev/null)\[\033[0m\]\[\033[$(__ps1_colour_escape $? $P4_COLOUR)m\]$(__ps1_p4 $? 2>/dev/null)\[\033[0m\]\[\033[$(__ps1_colour_escape $? $SVN_COLOUR)m\]$(__ps1_svn $? 2>/dev/null)\[\033[0m\]$(__ps1_ret $? 2>/dev/null):\w\$ ' return 0 } # iTerm doesn't like it if you set bold and colour at the same time. function __ps1_colour_escape() { + local ret=$1; shift local bold="${1%%;*}" local colour="${1#*;}" echo -en "${bold}m\033[$colour" + return $ret } function __ps1_col() { - [ $1 -gt 0 ] && __ps1_colour_escape "$PROMPT_FAILED_COLOUR" || __ps1_colour_escape "$PROMPT_OK_COLOUR" - return $1 + local ret=$1; shift + if [ $ret -gt 0 ]; then + __ps1_colour_escape $ret "$PROMPT_FAILED_COLOUR" + else + __ps1_colour_escape $ret "$PROMPT_OK_COLOUR" + fi + return $ret } function __ps1_ret() { -- 2.20.1