Skip to content

Instantly share code, notes, and snippets.

@Pallinder
Created June 7, 2012 22:26
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Pallinder/2892073 to your computer and use it in GitHub Desktop.
Save Pallinder/2892073 to your computer and use it in GitHub Desktop.
Add current git branch to fish
function parse_git_dirty
git diff --quiet HEAD ^&-
if test $status = 1
echo (set_color $fish_git_dirty_color)"Δ"(set_color normal)
end
end
function parse_git_branch
# git branch outputs lines, the current branch is prefixed with a *
set -l branch (git rev-parse --abbrev-ref HEAD)
echo $branch (parse_git_dirty)
end
function fish_prompt
if test -z (git branch --quiet 2>| awk '/fatal:/ {print "no git"}')
printf '%s%s%s (%s) $ ' (set_color $fish_color_cwd) (prompt_pwd) (set_color normal) (parse_git_branch)
else
printf '%s%s%s $ ' (set_color $fish_color_cwd) (prompt_pwd) (set_color normal)
end
@bergmark
Copy link

bergmark commented Feb 4, 2013

Nice, it just works!

@dag
Copy link

dag commented Feb 4, 2013

You could also try putting it in the fish_right_prompt function whose output is right-aligned. BTW I think an end is missing at the uhm, end?

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