Skip to content

Instantly share code, notes, and snippets.

@nemtsov
Last active January 23, 2019 04:02
Show Gist options
  • Save nemtsov/eccf190bf62462ab0b47898c1c75cc0b to your computer and use it in GitHub Desktop.
Save nemtsov/eccf190bf62462ab0b47898c1c75cc0b to your computer and use it in GitHub Desktop.
faster_git_fish_prompt.fish
function fish_prompt
set -l __last_command_exit_status $status
if not set -q -g __fish_yuriy_functions_defined
set -g __fish_yuriy_functions_defined
function _git_branch_name
set -l branch (git symbolic-ref --quiet HEAD ^/dev/null)
if set -q branch[1]
echo (string replace -r '^refs/heads/' '' $branch)
else
echo (git rev-parse --short HEAD ^/dev/null)
end
end
function _get_dirty_files
git status -s --ignore-submodules=dirty ^/dev/null
end
end
set -l cyan (set_color -o cyan)
set -l yellow (set_color -o yellow)
set -l red (set_color -o red)
set -l green (set_color -o green)
set -l blue (set_color -o blue)
set -l normal (set_color normal)
set -l arrow_color "$green"
if test $__last_command_exit_status != 0
set arrow_color "$red"
end
set -l arrow "$arrow_color➜ "
if test "$USER" = 'root'
set arrow "$arrow_color# "
end
set -l cwd $cyan(basename (prompt_pwd))
set -l dirty_files (_get_dirty_files)
if test $status -lt 1
set -l repo_branch $red(_git_branch_name)
set repo_info "$blue ($repo_branch$blue)"
if test -n "$dirty_files"
set -l dirty "$yellow ✗"
set repo_info "$repo_info$dirty"
end
end
echo -n -s $arrow ' '$cwd $repo_info $normal ' '
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment