diff options
author | Tom Ryder <tom@sanctum.geek.nz> | 2012-06-11 14:37:40 +1200 |
---|---|---|
committer | Tom Ryder <tom@sanctum.geek.nz> | 2012-06-11 14:37:40 +1200 |
commit | 1187f305f2f2e8b163013f45112b409ae64b684c (patch) | |
tree | a95df0080aea9d845253f5e17578776f8740a0bf /bash | |
parent | Suppress all errors (diff) | |
download | dotfiles-1187f305f2f2e8b163013f45112b409ae64b684c.tar.gz dotfiles-1187f305f2f2e8b163013f45112b409ae64b684c.zip |
Tidied VCS prompt functions
Diffstat (limited to 'bash')
-rw-r--r-- | bash/bashrc | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/bash/bashrc b/bash/bashrc index fde516b3..caed3242 100644 --- a/bash/bashrc +++ b/bash/bashrc @@ -90,10 +90,11 @@ fi # Function to display branch of a Git repository. function prompt_git { git branch &>/dev/null || return 1 - BRANCH="$(git symbolic-ref HEAD 2>/dev/null)" + HEAD="$(git symbolic-ref HEAD 2>/dev/null)" + BRANCH="${HEAD##*/}" [[ -n "$(git status 2>/dev/null | \ - grep 'working directory clean')" ]] || STATUS="!" - echo -n "(git:${BRANCH##*/}${STATUS})" + grep -F 'working directory clean')" ]] || STATUS="!" + echo -n "(git:${BRANCH:-unknown}${STATUS})" return 0 } @@ -103,9 +104,13 @@ function prompt_svn { URL="$(svn info 2>/dev/null | \ awk -F': ' '$1 == "URL" {print $2}')" ROOT="$(svn info 2>/dev/null | \ - awk -F': ' '$1 == "Repository Root" {print $2}')/" + awk -F': ' '$1 == "Repository Root" {print $2}')" + BRANCH=${URL/$ROOT} + BRANCH=${BRANCH#/} + BRANCH=${BRANCH#branches/} + BRANCH=${BRANCH%%/*} [[ -n "$(svn status 2>/dev/null)" ]] && STATUS="!" - echo -n "(svn:${URL/$ROOT}${STATUS})" + echo -n "(svn:${BRANCH:-unknown}${STATUS})" return 0 } @@ -114,7 +119,7 @@ function prompt_hg { hg branch &>/dev/null || return 1 BRANCH="$(hg branch 2>/dev/null)" [[ -n "$(hg status 2>/dev/null)" ]] && STATUS="!" - echo -n "(hg:${BRANCH}${STATUS})" + echo -n "(hg:${BRANCH:-unknown}${STATUS})" return 0 } |