From c4d61bb293287830d647d3be3bf518151ffecab1 Mon Sep 17 00:00:00 2001 From: ADAM David Alan Martin Date: Mon, 29 Jun 2026 10:17:38 -0400 Subject: [PATCH] Make git ahead and behind use one command. This reduces the number of forks per command line in git directories. --- tcshrc.prompt.final | 46 ++++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 26 deletions(-) diff --git a/tcshrc.prompt.final b/tcshrc.prompt.final index e75856c..cb66420 100644 --- a/tcshrc.prompt.final +++ b/tcshrc.prompt.final @@ -164,37 +164,31 @@ set __res=$? if( 0 == ${__res} ) then set git_branch=`git branch --show-current -q` >& /dev/null if( ! -z "${git_branch}" ) then - set branch_space=30 - set branch_indent=16 - #set git_branch_reserve=`echo ${git_branch} | wc -c` >& /dev/null - #set git_prompt="%{${csi}${branch_indent}C${csi}mBranch: ${csi}3;38;2;255;192;192m${git_branch}${csi}m${csi}${branch_space}C\n%}" + set git_counts=(`git rev-list --count --left-right \@\{upstream\}..HEAD`) + _debug "Got: ${git_counts}" + set git_behind_count=${git_counts[1]} + set git_ahead_count=${git_counts[2]} + #@ git_behind_count = ${git_behind_count} + 1 + _debug "Got: ${git_behind_count}" + _debug "Got: ${git_ahead_count}" + @ git_count_check = ${git_ahead_count} + ${git_behind_count} + if( 0 != ${git_count_check} ) then + set git_tracking_stat=": " - git rev-list --count --left-right \@\{upstream\}..HEAD>&/dev/null - set __res=$? - #echo "Got: ${git_counts}" - if( 0 == ${__res} ) then - set git_behind_count=`git rev-list --count --right-only HEAD..\@\{upstream\}` - #echo "Got: ${git_behind_count}" - set git_ahead_count=`git rev-list --count --right-only \@\{upstream\}..HEAD` - #echo "Got: ${git_ahead_count}" - if( 0 != ${git_behind_count} ) then - set git_tracking_stat=": -%{${behind_tracking_color_seq}%}${git_behind_count}%{${sgr_reset}%}" - if( 0 != ${git_ahead_count} ) then - set git_tracking_stat="${git_tracking_stat},+%{${ahead_tracking_color_seq}%}${git_ahead_count}%{${sgr_reset}%}" - endif - else - if( 0 != ${git_ahead_count} ) then - set git_tracking_stat=": +%{${ahead_tracking_color_seq}%}${git_ahead_count}%{${sgr_reset}%}" - endif - endif - endif + if( 0 != ${git_behind_count} ) then + set git_tracking_stat="${git_tracking_stat}-%{${behind_tracking_color_seq}%}${git_behind_count}%{${sgr_reset}%}" + endif + if( 0 != ${git_ahead_count} ) then + if( ${git_behind_count} != 0 ) then + set git_tracking_stat="${git_tracking_stat}," + endif + set git_tracking_stat="${git_tracking_stat}+%{${ahead_tracking_color_seq}%}${git_ahead_count}%{${sgr_reset}%}" + endif + endif set git_prompt="%{${sgr_reset}%}(${branch_symbol} %{${branch_color_seq}%}${git_branch}%{${sgr_reset}%}${git_tracking_stat}) " - #set git_prompt="%{${csi}10D${csi}2D(xyz${git_branch})${csi}m%%}" - #set git_prompt="%{${csi}0;35m${csi}50D${git_branch} %}" endif -else endif #set prompt_cool="%{\n%}${align_prefix}${battery_prefix}${battery_prompt}${date_prompt}${align_suffix}${git_prompt}${brace_color_seq}\[${prompt_reference}${line_prompt}${depth_prompt}${user_prompt}${at_color_seq}@${host_prompt}${text_color_seq}\: ${path_prompt}${brace_color_seq}\]${end_prompt}"