diff --git a/functions/_tide_item_git.fish b/functions/_tide_item_git.fish index 56e1e315..41d107e3 100644 --- a/functions/_tide_item_git.fish +++ b/functions/_tide_item_git.fish @@ -2,6 +2,7 @@ function _tide_item_git if git branch --show-current 2>/dev/null | string shorten -"$tide_git_truncation_strategy"m$tide_git_truncation_length | read -l location git rev-parse --git-dir --is-inside-git-dir | read -fL gdir in_gdir set location $_tide_location_color$location + test "$tide_git_hide_branch" = true && set -e location else if test $pipestatus[1] != 0 return else if git tag --points-at HEAD | string shorten -"$tide_git_truncation_strategy"m$tide_git_truncation_length | read location @@ -46,8 +47,8 @@ function _tide_item_git test $in_gdir = true && set -l _set_dir_opt -C $gdir/.. # Suppress errors in case we are in a bare repo or there is no upstream set -l stat (git $_set_dir_opt --no-optional-locks status --porcelain 2>/dev/null) - string match -qr '(0|(?.*))\n(0|(?.*))\n(0|(?.*)) -(0|(?.*))\n(0|(?.*))(\n(0|(?.*))\t(0|(?.*)))?' \ + string match -qr '(0|(?.+))\n(0|(?.+))\n(0|(?.+)) +(0|(?.+))\n(0|(?.+))(\n(0|(?.+))\t(0|(?.+)))?' \ "$(git $_set_dir_opt stash list 2>/dev/null | count string match -r ^UU $stat | count string match -r ^[ADMR] $stat | count @@ -61,12 +62,19 @@ function _tide_item_git set -g tide_git_bg_color $tide_git_bg_color_unstable end - _tide_print_item git $_tide_location_color$tide_git_icon' ' (set_color white; echo -ns $location - set_color $tide_git_color_operation; echo -ns ' '$operation ' '$step/$total_steps - set_color $tide_git_color_upstream; echo -ns ' ⇣'$behind ' ⇡'$ahead - set_color $tide_git_color_stash; echo -ns ' *'$stash - set_color $tide_git_color_conflicted; echo -ns ' ~'$conflicted - set_color $tide_git_color_staged; echo -ns ' +'$staged - set_color $tide_git_color_dirty; echo -ns ' !'$dirty - set_color $tide_git_color_untracked; echo -ns ' ?'$untracked) + set -l git_parts (begin + echo -s $_tide_location_color$tide_git_icon + echo -s (set_color white )$location + echo -s (set_color $tide_git_color_operation )$operation + echo -s (set_color $tide_git_color_operation )$step/$total_steps + echo -s (set_color $tide_git_color_upstream )'⇣'$behind + echo -s (set_color $tide_git_color_upstream )'⇡'$ahead + echo -s (set_color $tide_git_color_stash )'*'$stash + echo -s (set_color $tide_git_color_conflicted)'~'$conflicted + echo -s (set_color $tide_git_color_staged )'+'$staged + echo -s (set_color $tide_git_color_dirty )'!'$dirty + echo -s (set_color $tide_git_color_untracked )'?'$untracked + end | string join --no-empty ' ') + + _tide_print_item git $git_parts end diff --git a/functions/tide/configure/configs/classic.fish b/functions/tide/configure/configs/classic.fish index 2e1c2c76..3bf46ffb 100644 --- a/functions/tide/configure/configs/classic.fish +++ b/functions/tide/configure/configs/classic.fish @@ -42,6 +42,7 @@ tide_git_color_untracked $_tide_color_light_blue tide_git_color_upstream $_tide_color_green tide_git_truncation_length 24 tide_git_truncation_strategy +tide_git_hide_branch false tide_go_bg_color 444444 tide_go_color 00ACD7 tide_java_bg_color 444444 diff --git a/functions/tide/configure/configs/classic_16color.fish b/functions/tide/configure/configs/classic_16color.fish index fe730c5f..cfb04869 100644 --- a/functions/tide/configure/configs/classic_16color.fish +++ b/functions/tide/configure/configs/classic_16color.fish @@ -35,6 +35,7 @@ tide_git_color_staged bryellow tide_git_color_stash brgreen tide_git_color_untracked brblue tide_git_color_upstream brgreen +tide_git_hide_branch false tide_go_bg_color black tide_go_color brcyan tide_java_bg_color black diff --git a/functions/tide/configure/configs/lean.fish b/functions/tide/configure/configs/lean.fish index b9a97919..62c72fb7 100644 --- a/functions/tide/configure/configs/lean.fish +++ b/functions/tide/configure/configs/lean.fish @@ -42,6 +42,7 @@ tide_git_color_untracked $_tide_color_light_blue tide_git_color_upstream $_tide_color_green tide_git_truncation_length 24 tide_git_truncation_strategy +tide_git_hide_branch false tide_go_bg_color normal tide_go_color 00ACD7 tide_java_bg_color normal diff --git a/functions/tide/configure/configs/lean_16color.fish b/functions/tide/configure/configs/lean_16color.fish index 699ce45a..671b6f5f 100644 --- a/functions/tide/configure/configs/lean_16color.fish +++ b/functions/tide/configure/configs/lean_16color.fish @@ -35,6 +35,7 @@ tide_git_color_staged bryellow tide_git_color_stash brgreen tide_git_color_untracked brblue tide_git_color_upstream brgreen +tide_git_hide_branch false tide_go_bg_color normal tide_go_color brcyan tide_java_bg_color normal diff --git a/functions/tide/configure/configs/rainbow.fish b/functions/tide/configure/configs/rainbow.fish index 7c2ca30f..5a9039d0 100644 --- a/functions/tide/configure/configs/rainbow.fish +++ b/functions/tide/configure/configs/rainbow.fish @@ -42,6 +42,7 @@ tide_git_color_untracked 000000 tide_git_color_upstream 000000 tide_git_truncation_length 24 tide_git_truncation_strategy +tide_git_hide_branch false tide_go_bg_color 00ACD7 tide_go_color 000000 tide_java_bg_color ED8B00 diff --git a/functions/tide/configure/configs/rainbow_16color.fish b/functions/tide/configure/configs/rainbow_16color.fish index 5d206115..d0f21eef 100644 --- a/functions/tide/configure/configs/rainbow_16color.fish +++ b/functions/tide/configure/configs/rainbow_16color.fish @@ -35,6 +35,7 @@ tide_git_color_staged black tide_git_color_stash black tide_git_color_untracked black tide_git_color_upstream black +tide_git_hide_branch false tide_go_bg_color brcyan tide_go_color black tide_java_bg_color yellow diff --git a/tests/_tide_item_git.test.fish b/tests/_tide_item_git.test.fish index d3d7f605..1ad9ec4f 100644 --- a/tests/_tide_item_git.test.fish +++ b/tests/_tide_item_git.test.fish @@ -57,6 +57,31 @@ _git commit -am 'Append hello to foo' _git checkout HEAD~ _git_item # CHECK: {{@\w*}} +# --------- hide branch --------- +_git checkout main +echo >bar +_git_item # CHECK: main ?1 +set -lx tide_git_hide_branch true +_git_item # CHECK: ?1 + +# Mixed signs with hidden branch +_git add bar +echo modified >foo +_git_item # CHECK: +1 !1 + +# Verify tags still show when branch hiding enabled +_git reset --hard +_git tag v1.0 +_git checkout v1.0 +_git_item # CHECK: #v1.0 + +# Verify SHA still shows in detached HEAD +_git checkout HEAD~ +_git_item # CHECK: {{@\w*}} + +_git checkout main +set -lx tide_git_hide_branch false + # --- Long branches --- _git checkout main _git checkout -b very_long_branch_name