aboutsummaryrefslogtreecommitdiff
path: root/bash
diff options
context:
space:
mode:
authorTom Ryder <tom@sanctum.geek.nz>2013-07-03 14:57:27 +1200
committerTom Ryder <tom@sanctum.geek.nz>2013-07-03 14:57:27 +1200
commit805805fa9db9e115f502559e263ed54176bec7c7 (patch)
tree6f590b8b43f30664582e9642368c53e5d9faff0a /bash
parentExplicitly set timezone for profiles (diff)
downloaddotfiles-805805fa9db9e115f502559e263ed54176bec7c7.tar.gz
dotfiles-805805fa9db9e115f502559e263ed54176bec7c7.zip
Much-improved git prompt function
Thanks to @necolas: <https://github.com/necolas/dotfiles/blob/master/bash/bash_prompt#L60-L111>
Diffstat (limited to 'bash')
-rw-r--r--bash/bashrc.d/prompt.bash15
1 files changed, 12 insertions, 3 deletions
diff --git a/bash/bashrc.d/prompt.bash b/bash/bashrc.d/prompt.bash
index 346961a5..37d25ff3 100644
--- a/bash/bashrc.d/prompt.bash
+++ b/bash/bashrc.d/prompt.bash
@@ -29,11 +29,20 @@ function prompt {
# Git prompt function
git)
- git branch &>/dev/null || return 1
+ $(git rev-parse --is-inside-git-dir 2>/dev/null ) \
+ && return 1
+ $(git rev-parse --is-inside-work-tree 2>/dev/null ) \
+ || return 1
head="$(git symbolic-ref HEAD 2>/dev/null)"
branch="${head##*/}"
- [[ -n "$(git status 2>/dev/null | \
- grep -F 'nothing to commit')" ]] || state="!"
+ $(git diff --quiet --ignore-submodules --cached ) \
+ || state=${state}+
+ $(git diff-files --quiet --ignore-submodules -- ) \
+ || state=${state}!
+ $(git rev-parse --verify refs/stash &>/dev/null ) \
+ && state=${state}^
+ [ -n "$(git ls-files --others --exclude-standard )" ] \
+ && state=${state}?
printf '(git:%s)' "${branch:-unknown}${state}"
;;