mirror of
https://github.com/jimeh/git-aware-prompt.git
synced 2026-02-18 21:26:39 +00:00
Trying out some mods to this. Seems like speed is an issue with git rev-parse
This commit is contained in:
28
prompt.sh
28
prompt.sh
@@ -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\$ "
|
||||
|
||||
Reference in New Issue
Block a user