aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHaralan Dobrev <hkdobrev@gmail.com>2014-05-11 15:26:57 +0300
committerMathias Bynens <mathias@qiwi.be>2014-05-12 07:08:48 +0200
commit52abe37d2f9724e1d88a85cf6181b04a8dd756c4 (patch)
treeef50cadf7d3ec782c636e145d884d46de17f9ade
parent868ef43d1c33f06bffd2446ef01a18283c0f62ef (diff)
downloaddotfiles-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.
-rw-r--r--.bash_prompt14
-rw-r--r--README.md1
2 files changed, 9 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\]"
diff --git a/README.md b/README.md
index 102092b..e412d51 100644
--- a/README.md
+++ b/README.md
@@ -110,5 +110,6 @@ Suggestions/improvements
* [Sindre Sorhus](http://sindresorhus.com/)
* [Tom Ryder](http://blog.sanctum.geek.nz/) and his [dotfiles repository](https://github.com/tejr/dotfiles)
* [Kevin Suttle](http://kevinsuttle.com/) and his [dotfiles repository](https://github.com/kevinSuttle/dotfiles) and [OSXDefaults project](https://github.com/kevinSuttle/OSXDefaults), which aims to provide better documentation for [`~/.osx`](http://mths.be/osx)
+* [Haralan Dobrev](http://hkdobrev.com/)
* anyone who [contributed a patch](https://github.com/mathiasbynens/dotfiles/contributors) or [made a helpful suggestion](https://github.com/mathiasbynens/dotfiles/issues)