diff options
author | Haralan Dobrev <hkdobrev@gmail.com> | 2014-05-11 15:26:57 +0300 |
---|---|---|
committer | Mathias Bynens <mathias@qiwi.be> | 2014-05-12 07:08:48 +0200 |
commit | 52abe37d2f9724e1d88a85cf6181b04a8dd756c4 (patch) | |
tree | ef50cadf7d3ec782c636e145d884d46de17f9ade /.bash_prompt | |
parent | 868ef43d1c33f06bffd2446ef01a18283c0f62ef (diff) | |
download | dotfiles-52abe37d2f9724e1d88a85cf6181b04a8dd756c4.tar.gz dotfiles-52abe37d2f9724e1d88a85cf6181b04a8dd756c4.tar.bz2 dotfiles-52abe37d2f9724e1d88a85cf6181b04a8dd756c4.zip |
.bash_prompt: Speed up the Git commands for the prompt
Fixes #227 and closes #380.
Diffstat (limited to '.bash_prompt')
-rw-r--r-- | .bash_prompt | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/.bash_prompt b/.bash_prompt index 21c4b4b..83670e5 100644 --- a/.bash_prompt +++ b/.bash_prompt @@ -43,13 +43,15 @@ export WHITE export BOLD export RESET -function parse_git_dirty() { - [[ $(git status 2> /dev/null | tail -n1) != *"working directory clean"* ]] && echo "*" -} - function parse_git_branch() { - git branch --no-color 2> /dev/null | sed -e '/^[^*]/d' -e "s/* \(.*\)/\1$(parse_git_dirty)/" + local branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null) + if [ -n "${branch}" ]; then + [ "${branch}" == "HEAD" ] && local branch=$(git rev-parse --short HEAD 2>/dev/null) + local status=$(git status --porcelain 2>/dev/null) + echo -n " on ${PURPLE}${branch}" + [ -n "${status}" ] && echo -n "*" + fi } -export PS1="\[${BOLD}${MAGENTA}\]\u \[$WHITE\]at \[$ORANGE\]\h \[$WHITE\]in \[$GREEN\]\w\[$WHITE\]\$([[ -n \$(git branch 2> /dev/null) ]] && echo \" on \")\[$PURPLE\]\$(parse_git_branch)\[$WHITE\]\n\$ \[$RESET\]" +export PS1="\[${BOLD}${MAGENTA}\]\u \[$WHITE\]at \[$ORANGE\]\h \[$WHITE\]in \[$GREEN\]\w\[$WHITE\]\$(parse_git_branch)\[$WHITE\]\n\$ \[$RESET\]" export PS2="\[$ORANGE\]→ \[$RESET\]" |