oh-my-fish/themes/gitstatus/fish_prompt.fish

41 lines
995 B
Fish
Raw Normal View History

2013-10-28 00:33:46 +08:00
# name: GitStatus
# Find latest version from: https://github.com/godfat/fish_prompt-gitstatus
function _git_branch_name
echo (command git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
end
function _git_status_symbol
set -l git_status (git status --porcelain ^/dev/null)
if test -n "$git_status"
# Is there anyway to preserve newlines so we can reuse $git_status?
if git status --porcelain ^/dev/null | grep '^.[^ ]' >/dev/null
echo '*' # dirty
else
echo '#' # all staged
end
else
echo '' # clean
end
end
function _remote_hostname
if test -n "$SSH_CONNECTION"
2013-10-28 00:33:46 +08:00
echo (whoami)@(hostname)
end
end
function fish_prompt
set -l cyan (set_color cyan)
set -l normal (set_color normal)
2013-10-28 00:33:46 +08:00
set -l cwd (set_color $fish_color_cwd)(prompt_pwd)
set -l git_status (_git_status_symbol)(_git_branch_name)
if test -n "$git_status"
set git_status " $git_status"
end
2013-10-28 00:33:46 +08:00
echo -n (_remote_hostname) $cwd$cyan$git_status$normal'> '
2013-10-28 00:33:46 +08:00
end