fish: mark branches with deleted remote

This commit is contained in:
Leonardo Eugênio 2026-03-03 23:17:23 -03:00
parent d038605de9
commit ff74e9ec4a

View file

@ -63,6 +63,21 @@ function _fish_prompt_git_unpushed_branches
string split ', ' string split ', '
end end
function _fish_prompt_git_remote_deleted -a git_branch
set -l git_remote (git config --get "branch.$git_branch.remote" 2> /dev/null)
set -l git_merge_ref (git config --get "branch.$git_branch.merge" 2> /dev/null)
test -n "$git_remote"
and test -n "$git_merge_ref"
or return 1
set -l git_remote_ref "refs/remotes/$git_remote/"(string replace -r '^refs/heads/' '' "$git_merge_ref")
git show-ref --verify --quiet "$git_remote_ref"
and return 1
return 0
end
function fish_git_prompt function fish_git_prompt
command -qs git command -qs git
or return or return
@ -81,6 +96,7 @@ function fish_git_prompt
set -l git_branch (git branch --show-current 2> /dev/null);or return set -l git_branch (git branch --show-current 2> /dev/null);or return
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_remote_deleted (_fish_prompt_git_remote_deleted "$git_branch"; and echo "1")
set -l git_status_s (timeout 5s git status -s | string collect) set -l git_status_s (timeout 5s git status -s | string collect)
set -l git_log_unpushed (_fish_prompt_git_unpushed_branches) set -l git_log_unpushed (_fish_prompt_git_unpushed_branches)
@ -100,26 +116,33 @@ function fish_git_prompt
_fish_prompt_warn "$git_detach" _fish_prompt_warn "$git_detach"
else if test -n "$git_branch" else if test -n "$git_branch"
_fish_prompt_accent "$git_branch" _fish_prompt_accent "$git_branch"
if test -n "$git_remote_deleted"
_fish_prompt_warn "X"
end
else else
_fish_prompt_warn "init" _fish_prompt_warn "init"
end end
# if we have at least one commit # if we have at least one commit
if git rev-parse HEAD -- &>/dev/null if git rev-parse HEAD -- &>/dev/null
# print a "↑" if ahead of origin # Only compare ahead/behind when upstream exists and resolves correctly.
test 0 -ne (git log --oneline "$git_remote_branch"..HEAD -- | wc -l) if test -n "$git_remote_branch"
and set -f _git_sync_ahead '↑' and git rev-parse --verify "$git_remote_branch" &>/dev/null
# print a "↑" if ahead of origin
test 0 -ne (git log --oneline "$git_remote_branch"..HEAD -- | wc -l)
and set -f _git_sync_ahead '↑'
# 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)
and set -l _git_sync_behind '↓' and set -l _git_sync_behind '↓'
if set -q _git_sync_ahead _git_sync_behind if set -q _git_sync_ahead _git_sync_behind
_fish_prompt_normal '⇅' _fish_prompt_normal '⇅'
else if set -q _git_sync_ahead else if set -q _git_sync_ahead
_fish_prompt_normal '↑' _fish_prompt_normal '↑'
else if set -q _git_sync_behind else if set -q _git_sync_behind
_fish_prompt_normal '↓' _fish_prompt_normal '↓'
end
end end
if test -n "$git_log_unpushed" if test -n "$git_log_unpushed"