Trying out some mods to this. Seems like speed is an issue with git rev-parse

This commit is contained in:
eacousineau
2013-03-19 14:05:02 -05:00
parent e20cea24a8
commit 1b027dafef

View File

@@ -1,20 +1,14 @@
function find_git_branch {
local dir=. head
until [ "$dir" -ef / ]; do
if [ -f "$dir/.git/HEAD" ]; then
head=$(< "$dir/.git/HEAD")
if [[ $head == ref:\ refs/heads/* ]]; then
git_branch=" (${head#*/*/})"
elif [[ $head != '' ]]; then
git_branch=' (detached)'
else
git_branch=' (unknown)'
fi
return
fi
dir="../$dir"
done
git_branch=''
local dir=. head branch
if branch=$(git rev-parse --abbrev-ref HEAD 2> /dev/null)
then
if [[ -z "$branch" ]]; then
branch='detached'
fi
git_branch=" ($branch)"
else
git_branch=""
fi
}
function find_git_dirty {
st=$(git status 2>/dev/null | tail -n 1)
@@ -32,4 +26,4 @@ PROMPT_COMMAND="find_git_branch; find_git_dirty; $PROMPT_COMMAND"
# export PS1="\u@\h \w\[$txtcyn\]\$git_branch\[$txtylw\]\$git_dirty\[$txtrst\]\$ "
# Default Git enabled root prompt (for use with "sudo -s")
# export SUDO_PS1="\[$bakred\]\u@\h\[$txtrst\] \w\$ "
# export SUDO_PS1="\[$bakred\]\u@\h\[$txtrst\] \w\$ "