dotfiles/terminal/fish/functions/fish_right_prompt.fish
2017-10-15 20:50:00 +02:00

35 lines
730 B
Fish
Executable File

function fish_right_prompt
# Check if we are inside a version controlled directory (git only)
set -l ref (git symbolic-ref HEAD ^/dev/null)
if test -z $ref
return
end
# Check if any files have changes
git diff --no-ext-diff --quiet --exit-code ^/dev/null
or set -l dirty 'yes'
# Check if any files are staged
git diff-index --cached --quiet HEAD -- ^/dev/null
or set -l staged 'yes'
set_color normal
echo -sn '['
# Print branch name
# red if dirty
# yellow if staged
# green otherwise
if set -q staged
set_color yellow
else if set -q dirty
set_color red
else
set_color green
end
echo -sn (string replace refs/heads/ '' -- $ref)
set_color normal
echo -sn ']'
end