git info bash plugin refactor; now first check the existance of the HEAD refs instead of running git status right away
This commit is contained in:
parent
c9809b7a45
commit
61d88eeddb
1 changed files with 15 additions and 18 deletions
25
bashplugins
25
bashplugins
|
@ -40,20 +40,17 @@ gdf()
|
||||||
|
|
||||||
git_prompt()
|
git_prompt()
|
||||||
{
|
{
|
||||||
local staged_count unstaged_count untracked_count unmerged_count
|
|
||||||
local git_status branch_info full_status IFS=
|
|
||||||
|
|
||||||
prompt_command
|
prompt_command
|
||||||
|
|
||||||
if ! raw_status="$(git status --porcelain -bu 2>/dev/null)"; then
|
if [[ ! -r ./.git/HEAD ]] || ! local raw_status="$(git status --porcelain -bu 2>/dev/null)"; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
local branch_info full_status IFS=
|
||||||
git_status=''
|
local git_status=''
|
||||||
staged_count=0
|
local staged_count=0
|
||||||
unstaged_count=0
|
local unstaged_count=0
|
||||||
untracked_count=0
|
local untracked_count=0
|
||||||
unmerged_count=0
|
local unmerged_count=0
|
||||||
|
|
||||||
while read line; do
|
while read line; do
|
||||||
[[ "${line:0:2}" == '##' ]] && branch_info="${line:3}"
|
[[ "${line:0:2}" == '##' ]] && branch_info="${line:3}"
|
||||||
|
@ -63,10 +60,10 @@ git_prompt()
|
||||||
[[ "${line:0:2}" =~ (U[ADU]|A[AU]|D[DU]) ]] && (( unmerged_count++ ))
|
[[ "${line:0:2}" =~ (U[ADU]|A[AU]|D[DU]) ]] && (( unmerged_count++ ))
|
||||||
done <<< "${raw_status}"
|
done <<< "${raw_status}"
|
||||||
|
|
||||||
(( $unstaged_count > 0 )) && git_status+="${ppurple}~${unstaged_count}"
|
(( unstaged_count )) && git_status+="${ppurple}~${unstaged_count}"
|
||||||
(( $staged_count > 0 )) && git_status+="${pblue}+${staged_count}"
|
(( staged_count )) && git_status+="${pblue}+${staged_count}"
|
||||||
(( $untracked_count > 0 )) && git_status+="${pred}-${untracked_count}"
|
(( untracked_count )) && git_status+="${pred}-${untracked_count}"
|
||||||
(( $unmerged_count > 0 )) && git_status+="${porange}*${unmerged_count}"
|
(( unmerged_count )) && git_status+="${porange}*${unmerged_count}"
|
||||||
[[ -z "${git_status}" ]] && git_status="${pgreen}ok"
|
[[ -z "${git_status}" ]] && git_status="${pgreen}ok"
|
||||||
|
|
||||||
full_status="{ ${pgray3}${branch_info}${preset} | ${git_status}${preset} }"
|
full_status="{ ${pgray3}${branch_info}${preset} | ${git_status}${preset} }"
|
||||||
|
|
Loading…
Reference in a new issue