bash_aliases: rework prompt_ps1_git_branch again
- avoid pipe to grep to find current branch line - use local variables - update to support git 2.x format for current branch detached-HEAD format
This commit is contained in:
parent
18ce273e18
commit
7309c0b32c
24
bash_aliases
24
bash_aliases
@ -14,20 +14,24 @@ fi
|
|||||||
|
|
||||||
function prompt_ps1_git_branch()
|
function prompt_ps1_git_branch()
|
||||||
{
|
{
|
||||||
|
local git_branch_out
|
||||||
|
local git_branch_out_line
|
||||||
if [ -e .git ]; then
|
if [ -e .git ]; then
|
||||||
branch_out=$(command git branch -vv 2>/dev/null | grep '^\*')
|
git_branch_out=$(command git branch -vv 2>/dev/null)
|
||||||
if [[ "$branch_out" == "" ]]; then
|
if [[ "$git_branch_out" == "" ]]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
re="^\\* (\\((detached|no.branch)[^)]*\\)|[^ ]*)"
|
local re="^\\* (\\(([^)]*)\\)|([^ ]*))"
|
||||||
if [[ "$branch_out" =~ $re ]]; then
|
while read -r git_branch_out_line; do
|
||||||
current_branch="${BASH_REMATCH[1]}"
|
if [[ "$git_branch_out_line" =~ $re ]]; then
|
||||||
re="((ahead|behind)[^]]*)\\]"
|
local current_branch="${BASH_REMATCH[2]:-${BASH_REMATCH[3]}}"
|
||||||
if [[ "$branch_out" =~ $re ]]; then
|
re="((ahead|behind)[^]]*)\\]"
|
||||||
current_branch="$current_branch: ${BASH_REMATCH[1]}"
|
if [[ "$git_branch_out" =~ $re ]]; then
|
||||||
|
current_branch="$current_branch: ${BASH_REMATCH[1]}"
|
||||||
|
fi
|
||||||
|
echo " [${current_branch}${ahead_behind}]"
|
||||||
fi
|
fi
|
||||||
echo " [${current_branch}${ahead_behind}]"
|
done <<< "$git_branch_out"
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user