Skip to content

Instantly share code, notes, and snippets.

@yuhua-chen
Created July 13, 2014 16:04
Show Gist options
  • Save yuhua-chen/427caefcb0873918fb99 to your computer and use it in GitHub Desktop.
Save yuhua-chen/427caefcb0873918fb99 to your computer and use it in GitHub Desktop.
Showing git branch in fish shell prompt
set fish_git_dirty_color red
set fish_git_not_dirty_color green
function parse_git_branch
set -l branch (git branch 2> /dev/null | grep -e '\* ' | sed 's/^..\(.*\)/\1/')
set -l git_diff (git diff)
if test -n "$git_diff"
echo (set_color $fish_git_dirty_color)$branch(set_color normal)
else
echo (set_color $fish_git_not_dirty_color)$branch(set_color normal)
end
end
function fish_prompt
if test -d .git
printf '%s@%s %s%s%s:%s> ' (whoami) (hostname|cut -d . -f 1) (set_color $fish_color_cwd) (prompt_pwd) (set_color normal) (parse_git_branch)
else
printf '%s@%s %s%s%s> ' (whoami) (hostname|cut -d . -f 1) (set_color $fish_color_cwd) (prompt_pwd) (set_color normal)
end
end
@yuhua-chen
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment