From 52abe37d2f9724e1d88a85cf6181b04a8dd756c4 Mon Sep 17 00:00:00 2001 From: Haralan Dobrev Date: Sun, 11 May 2014 15:26:57 +0300 Subject: .bash_prompt: Speed up the Git commands for the prompt Fixes #227 and closes #380. --- .bash_prompt | 14 ++++++++------ README.md | 1 + 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) -- cgit v1.2.3