fish: add special icon for unpushed branches

This commit is contained in:
Leonardo Eugênio 2023-05-04 00:35:18 -03:00
parent e1dc83286a
commit 8d980ed634

View file

@ -47,7 +47,17 @@ function _fish_prompt_git_remote_branches
end end
function _fish_prompt_git_unpushed_branches 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 end
function fish_git_prompt function fish_git_prompt
@ -69,7 +79,7 @@ function fish_git_prompt
set -l git_detach (_fish_prompt_git_detached) 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_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_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 " _fish_prompt_normal " on "
@ -95,10 +105,8 @@ function fish_git_prompt
or return or return
# print a "↑" if ahead of origin # print a "↑" if ahead of origin
if test 0 -ne (git log --oneline "$git_remote_branch"..HEAD -- | wc -l) test 0 -ne (git log --oneline "$git_remote_branch"..HEAD -- | wc -l)
or test 0 -ne "$git_log_unpushed" and set -f _git_sync_ahead '↑'
set -f _git_sync_ahead '↑'
end
# print a "↓" if behind of origin # print a "↓" if behind of origin
test 0 -lt (git log --oneline HEAD.."$git_remote_branch" -- | wc -l) test 0 -lt (git log --oneline HEAD.."$git_remote_branch" -- | wc -l)
@ -112,6 +120,12 @@ function fish_git_prompt
_fish_prompt_normal '↓' _fish_prompt_normal '↓'
end 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 # Right side represents WorkTree/Staged
############################################################ ############################################################