From 8d980ed63451938eeb5f90b558676349c91f32c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonardo=20Eug=C3=AAnio?= Date: Thu, 4 May 2023 00:35:18 -0300 Subject: [PATCH] fish: add special icon for unpushed branches --- user/fish/fish_prompt.fish | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/user/fish/fish_prompt.fish b/user/fish/fish_prompt.fish index 6161362..35cfd32 100644 --- a/user/fish/fish_prompt.fish +++ b/user/fish/fish_prompt.fish @@ -47,7 +47,17 @@ function _fish_prompt_git_remote_branches end function _fish_prompt_git_unpushed_branches - timeout 1s git log --branches --not --remotes --no-walk --oneline + timeout 1s git log \ + --branches \ + --simplify-by-decoration \ + --not \ + --remotes \ + --no-walk \ + --oneline \ + --decorate \ + --pretty=format:%D | + string replace 'HEAD -> ' '' | + string split ', ' end function fish_git_prompt @@ -69,7 +79,7 @@ function fish_git_prompt set -l git_detach (_fish_prompt_git_detached) set -l git_remote_branch (git rev-parse --abbrev-ref (git branch --show-current)@{u} 2> /dev/null) set -l git_status_s (timeout 1s git status -s | string collect) - set -l git_log_unpushed (_fish_prompt_git_unpushed_branches | wc -l) + set -l git_log_unpushed (_fish_prompt_git_unpushed_branches) _fish_prompt_normal " on " @@ -95,10 +105,8 @@ function fish_git_prompt or return # print a "↑" if ahead of origin - if test 0 -ne (git log --oneline "$git_remote_branch"..HEAD -- | wc -l) - or test 0 -ne "$git_log_unpushed" - set -f _git_sync_ahead '↑' - end + test 0 -ne (git log --oneline "$git_remote_branch"..HEAD -- | wc -l) + and set -f _git_sync_ahead '↑' # print a "↓" if behind of origin test 0 -lt (git log --oneline HEAD.."$git_remote_branch" -- | wc -l) @@ -112,6 +120,12 @@ function fish_git_prompt _fish_prompt_normal '↓' end + if test -n "$git_log_unpushed" + and not string match -qr "$git_branch" "$git_log_unpushed" + _fish_prompt_normal '↻' + _fish_prompt_warn $git_log_unpushed[1] + end + ############################################################ # Right side represents WorkTree/Staged ############################################################