1
0
Fork 0
vdotfiles/cli/.config/fish/functions/fish_prompt.git.fish

22 lines
1.3 KiB
Fish
Raw Permalink Normal View History

2024-09-10 12:22:46 +03:00
function fish_prompt.git
set -l is_git_tree (git rev-parse --is-inside-work-tree 2>/dev/null)
string match -qe 'true' "$is_git_tree" || return
2023-02-05 22:13:01 +02:00
git status --porcelain -bu | while read line
if string match -qr '^##' "$line"
2023-02-06 13:38:34 +02:00
set git_branch (string match -r '[^# .]+' "$line")
2023-02-05 22:13:01 +02:00
string match -qr '\[behind' $line && set git_branch "$git_branch?"
string match -qr '\[ahead' $line && set git_branch "$git_branch!"
2024-11-11 12:07:22 +02:00
fish_prompt.add "$git_symbol $git_branch"
2023-02-05 22:13:01 +02:00
else
string match -qr "^.[MD]" "$line" && set git_count[1] (math $git_count[1] + 1)
string match -qr "^[MDARC]." "$line" && set git_count[2] (math $git_count[2] + 1)
string match -qr "^\?\?" "$line" && set git_count[3] (math $git_count[3] + 1)
string match -qr "^[ADU]{2}" "$line" && set git_count[4] (math $git_count[4] + 1)
end
end
2024-09-10 12:22:46 +03:00
test -n "$git_count[1]" && fish_prompt.add "$git_count[1]$git_status[1]" "$color_git[1]"
test -n "$git_count[2]" && fish_prompt.add "$git_count[2]$git_status[2]" "$color_git[2]"
test -n "$git_count[3]" && fish_prompt.add "$git_count[3]$git_status[3]" "$color_git[3]"
test -n "$git_count[4]" && fish_prompt.add "$git_count[4]$git_status[4]" "$color_git[4]"
2023-02-05 22:13:01 +02:00
end