mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-29 14:23:09 +00:00
0116dc5984
Deletes the error message generated by git when comparing indexes for a commitless repository and print '-' as the branch name
56 lines
2.3 KiB
Fish
56 lines
2.3 KiB
Fish
# name: Acidhub
|
|
# author: Acidhub - https://acidhub.click/
|
|
|
|
function fish_prompt -d "Write out the prompt"
|
|
set -l laststatus $status
|
|
|
|
set -l git_info
|
|
if set -l git_branch (command git branch --format=%\(refname:lstrip=2\) 2> /dev/null)
|
|
set -l git_status
|
|
if test -n "$git_branch"; and not command git diff-index --quiet HEAD --
|
|
if set -l count (command git rev-list --count --left-right $upstream...HEAD 2>/dev/null)
|
|
echo $count | read -l ahead behind
|
|
if test "$ahead" -gt 0
|
|
set git_status "$git_status"(set_color red)⬆
|
|
end
|
|
if test "$behind" -gt 0
|
|
set git_status "$git_status"(set_color red)⬇
|
|
end
|
|
end
|
|
for i in (git status --porcelain | string sub -l 2 | sort | uniq)
|
|
switch $i
|
|
case "."
|
|
set git_status "$git_status"(set_color green)✚
|
|
case " D"
|
|
set git_status "$git_status"(set_color red)✖
|
|
case "*M*"
|
|
set git_status "$git_status"(set_color green)✱
|
|
case "*R*"
|
|
set git_status "$git_status"(set_color purple)➜
|
|
case "*U*"
|
|
set git_status "$git_status"(set_color brown)═
|
|
case "??"
|
|
set git_status "$git_status"(set_color red)≠
|
|
end
|
|
end
|
|
else
|
|
set git_status (set_color green):
|
|
if test -z "$git_branch"
|
|
set git_branch "-"
|
|
end
|
|
end
|
|
set git_info "(git$git_status"(set_color -o blue)"$git_branch"(set_color white)")"
|
|
end
|
|
|
|
# Disable PWD shortening by default.
|
|
set -q fish_prompt_pwd_dir_length
|
|
or set -lx fish_prompt_pwd_dir_length 0
|
|
|
|
set_color -b black
|
|
printf '%s%s%s%s%s%s%s%s%s%s%s%s%s' (set_color -o white) '❰' (set_color green) $USER (set_color white) '❙' (set_color yellow) (prompt_pwd) (set_color white) $git_info (set_color white) '❱' (set_color white)
|
|
if test $laststatus -eq 0
|
|
printf "%s✔%s≻%s " (set_color -o green) (set_color white) (set_color normal)
|
|
else
|
|
printf "%s✘%s≻%s " (set_color -o red) (set_color white) (set_color normal)
|
|
end
|
|
end
|