fish: mark branches with deleted remote
This commit is contained in:
parent
d038605de9
commit
ff74e9ec4a
1 changed files with 35 additions and 12 deletions
|
|
@ -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,12 +116,18 @@ 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
|
||||||
|
# Only compare ahead/behind when upstream exists and resolves correctly.
|
||||||
|
if test -n "$git_remote_branch"
|
||||||
|
and git rev-parse --verify "$git_remote_branch" &>/dev/null
|
||||||
# print a "↑" if ahead of origin
|
# print a "↑" if ahead of origin
|
||||||
test 0 -ne (git log --oneline "$git_remote_branch"..HEAD -- | wc -l)
|
test 0 -ne (git log --oneline "$git_remote_branch"..HEAD -- | wc -l)
|
||||||
and set -f _git_sync_ahead '↑'
|
and set -f _git_sync_ahead '↑'
|
||||||
|
|
@ -121,6 +143,7 @@ function fish_git_prompt
|
||||||
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"
|
||||||
and not string match -qr "$git_branch" "$git_log_unpushed"
|
and not string match -qr "$git_branch" "$git_log_unpushed"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue