X-Git-Url: http://git.iain.cx/?a=blobdiff_plain;f=.profile.d%2Fps1.bashrc;h=b65e42d8447e3c3b91a00d4ddec329ed548ae59a;hb=8fbd163e15300ebf2df0789cf0a9c66b415c5ce1;hp=436cd8cd1285c58398fa71baa016209b9a2fea8c;hpb=9b2d4a12c4cbeea017e1abdd506bf9dcdc5b4910;p=profile.git diff --git a/.profile.d/ps1.bashrc b/.profile.d/ps1.bashrc index 436cd8c..b65e42d 100644 --- a/.profile.d/ps1.bashrc +++ b/.profile.d/ps1.bashrc @@ -16,7 +16,10 @@ # The third part of the prompt is taken from p4-completion.bashrc. # It is shown only if __ps1_p4 is 1. By default it is 0. # -# The fourth part of the prompt is the exit status of the last command. +# The fourth part of the prompt is taken from svn-completion.bashrc. +# It is shown only if __ps1_svn is 1. By default it is 0. +# +# The fifth part of the prompt is the exit status of the last command. # This part will be shown only if __ps1_user is set and the exit status is # non-zero. # @@ -39,26 +42,30 @@ # Failed: dark red. # Git: royal blue. # P4: yellow. +# SVN: magenta. case $(tput colors) in 256) - export PROMPT_OK_COLOUR="1;38;5;34" - export PROMPT_FAILED_COLOUR="1;38;5;160" - export GIT_COLOUR="0;38;5;33" - export P4_COLOUR="0;38;5;142" + PROMPT_OK_COLOUR="1;38;5;34" + PROMPT_FAILED_COLOUR="1;38;5;160" + GIT_COLOUR="0;38;5;33" + SVN_COLOUR="0;38;5;127" + P4_COLOUR="0;38;5;142" ;; 88) - export PROMPT_OK_COLOUR="1;38;5;24" - export PROMPT_FAILED_COLOUR="1;38;5;48" - export GIT_COLOUR="0;38;5;23" - export P4_COLOUR="0;38;5;56" + PROMPT_OK_COLOUR="1;38;5;24" + PROMPT_FAILED_COLOUR="1;38;5;48" + GIT_COLOUR="0;38;5;23" + SVN_COLOUR="0;38;5;49" + P4_COLOUR="0;38;5;56" ;; *) - export PROMPT_OK_COLOUR="1;32" - export PROMPT_FAILED_COLOUR="1;31" - export GIT_COLOUR="0;36" - export P4_COLOUR="0;33" + PROMPT_OK_COLOUR="1;32" + PROMPT_FAILED_COLOUR="1;31" + GIT_COLOUR="0;36" + SVN_COLOUR="0;35" + P4_COLOUR="0;33" ;; esac @@ -66,13 +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[${GIT_COLOUR}m\]$(__ps1_git $? 2>/dev/null)\[\033[0m\]\[\033[${P4_COLOUR}m\]$(__ps1_p4 $? 2>/dev/null)\[\033[0m\]$(__ps1_ret $? 2>/dev/null):\w\$ ' + 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 ] && echo -n "$PROMPT_FAILED_COLOUR" || echo -n "$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() { @@ -108,6 +130,16 @@ function __ps1_p4() { return $1 } +function __ps1_svn() { + [ "$__ps1_svn" = "1" ] || return $1 + if [ "$__ps1_user" = "1" -o "$__ps1_git" = "1" -o "$__ps1_p4" = "1" ]; then + __svn_ps1 ' %s' + else + __svn_ps1 '%s' + fi + return $1 +} + function prompt() { local blurb="Usage: prompt hide|show "