From 1a4ea1bd0f41ce7d2f636f15412e2b344e3cd83e Mon Sep 17 00:00:00 2001 From: Von Random Date: Wed, 1 Mar 2017 20:26:42 +0300 Subject: [PATCH] fix wrong staged status detection, add a way to debug the thing --- bashplugins | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/bashplugins b/bashplugins index 40260de..8bb3e67 100644 --- a/bashplugins +++ b/bashplugins @@ -25,9 +25,6 @@ gdf() git_prompt() { - # FIXME: - # upon the first traverse into the git repository, we always get staged - # count instead of unstaged, that is weird prompt_command if ! raw_status="$(git status --porcelain -bu 2>/dev/null)"; then return @@ -38,6 +35,8 @@ git_prompt() untracked_count=0 unmerged_count=0 + IFS= + while read line; do if [[ "${line:0:2}" == '##' ]]; then read branch_info <<< "${line:3}" @@ -49,14 +48,17 @@ git_prompt() done <<< "${raw_status}" (( $unstaged_count > 0 )) && git_status+="${pmagenta}~${unstaged_count}" - (( $staged_count > 0 )) && git_status+="${pyellow}+${staged_count}" - (( $untracked_count > 0 )) && git_status+="${pcyan}?${untracked_count}" - (( $unmerged_count > 0 )) && git_status+="${pred}!${unmerged_count}" + (( $staged_count > 0 )) && git_status+="${pgreen}+${staged_count}" + (( $untracked_count > 0 )) && git_status+="${pyellow}-${untracked_count}" + (( $unmerged_count > 0 )) && git_status+="${pred}*${unmerged_count}" [[ -z "${git_status}" ]] && git_status='.' full_status="{ ${pblue}${branch_info}${preset} | ${git_status}${preset} }" - IFS="$ifs_temp" - PS1="${ps_line1} ${full_status}\n${ps_line2}" + if [[ -n "${OLD_PROMPT}" ]]; then + PS1="${ps_line1} ${full_status}\n${ps_line2}" + else + echo ${full_status} + fi } gitmode() @@ -69,3 +71,5 @@ gitmode() PROMPT_COMMAND=git_prompt fi } + +gitmode