significantly speed up showing git/svn branch in bash prompt
This commit is contained in:
parent
50189f2e16
commit
d48d5d7157
37
bash_aliases
37
bash_aliases
@ -34,38 +34,35 @@ alias cdshowgitstatus='if [[ $CDSHOWGITSTATUS_LAST_WD != $PWD ]]; then if [[ -e
|
|||||||
PROMPT_COMMAND="cdshowgitstatus;$PROMPT_COMMAND"
|
PROMPT_COMMAND="cdshowgitstatus;$PROMPT_COMMAND"
|
||||||
function prompt_ps1_git_branch()
|
function prompt_ps1_git_branch()
|
||||||
{
|
{
|
||||||
which_git=$(which git)
|
if [ -e .git ]; then
|
||||||
if [[ "$which_git" == "" ]]; then
|
branch_out=$(command git branch -vv 2>/dev/null | grep '^\*')
|
||||||
return
|
|
||||||
fi
|
|
||||||
branch_out=$(command git branch -vv 2>/dev/null | grep '^\*' | sed -e 's/^..//')
|
|
||||||
if [[ "$branch_out" == "" ]]; then
|
if [[ "$branch_out" == "" ]]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
current_branch=$(echo "$branch_out" | sed -re 's/(.no.branch.|[^ ]*).*/\1/')
|
re="^\\* (.no.branch.|[^ ]*)"
|
||||||
ahead_behind=$(echo "$branch_out" | grep -E '(ahead|behind)' | grep -Eo '\[.*\]' | grep -Eo '(ahead|behind)[^]]*')
|
if [[ "$branch_out" =~ $re ]]; then
|
||||||
if [[ "$ahead_behind" != "" ]]; then
|
current_branch="${BASH_REMATCH[1]}"
|
||||||
ahead_behind=": ${ahead_behind}"
|
re="((ahead|behind).*)\\]"
|
||||||
|
if [[ "$branch_out" =~ $re ]]; then
|
||||||
|
current_branch="$current_branch: ${BASH_REMATCH[1]}"
|
||||||
fi
|
fi
|
||||||
if [[ "$branch_out" != "" ]]; then
|
echo " [${current_branch}${ahead_behind}]"
|
||||||
if [[ "$current_branch" != "" ]]; then
|
|
||||||
echo -e " [${current_branch}${ahead_behind}]"
|
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
#put $(prompt_ps1_git_branch) in $PS1 to use it
|
#put $(prompt_ps1_git_branch) in $PS1 to use it
|
||||||
function prompt_ps1_svn_branch()
|
function prompt_ps1_svn_branch()
|
||||||
{
|
{
|
||||||
which_svn=$(which svn)
|
if [ -e .svn ]; then
|
||||||
if [[ "$which_svn" == "" ]]; then
|
url_out=$(command svn info 2>/dev/null | grep '^URL:')
|
||||||
return
|
re_branch="\\<(tags|branches)/([^/]*)\\>"
|
||||||
|
re_trunk="\\<trunk\\>"
|
||||||
|
if [[ "$url_out" =~ $re_branch ]]; then
|
||||||
|
echo " [${BASH_REMATCH[2]}]"
|
||||||
|
elif [[ "$url_out" =~ $re_trunk ]]; then
|
||||||
|
echo " [${BASH_REMATCH[0]}]"
|
||||||
fi
|
fi
|
||||||
url_out=$(command svn info 2>/dev/null | grep '^URL:' | grep -E '\<(trunk|tags|branches)\>')
|
|
||||||
if [[ "$url_out" == "" ]]; then
|
|
||||||
return
|
|
||||||
fi
|
fi
|
||||||
filter=$(echo "$url_out" | sed -re 's/.*\<trunk\>.*$/trunk/' -e 's/.*\<(tags|branches)\/([^\/]*).*$/\2/')
|
|
||||||
echo " [${filter}]"
|
|
||||||
}
|
}
|
||||||
alias ls='ls --color=auto'
|
alias ls='ls --color=auto'
|
||||||
alias strip-cr="sed -e 's/\x0d//'"
|
alias strip-cr="sed -e 's/\x0d//'"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user