Display git branch and ‘dirty’ status in fish shell prompt

UPDATE: due to this bug which exists in the version fish I got from macports, I decided against fish. It’s a bad sign when you find that bad of a bug in your first few minutes of using something.

Dissatisfaction with the bash shell, and the feature list and humorous promotion of the new fish shell fork ("Finally, a command line shell for the 90s… You’ll have an astonishing 256 colors available for use!") spurred me to try fish out for a few days. It’ll have to be a lot better than bash to make worthwhile leaving the large bash community and its google-able answers. We’ll see.

The customization in my bash .profile I can’t live without [1] is showing the current git branch in the command prompt. Googling this feature for fish got me most of the way there, with the code found here: https://wiki.archlinux.org/index.php/Fish#Configuration_Suggestions . But it didn’t quite work.  Below is what I got to work. As it also shows if you have staged or unstaged changes I like it better than what I had in bash.

set fish_git_dirty_color red

function parse_git_dirty 

         git diff —quiet HEAD ^&-

         if test $status = 1

            echo (set_color $fish_git_dirty_color)”Δ”(set_color normal)



function parse_git_branch

         # git branch outputs lines, the current branch is prefixed with a *

         set -l branch (git branch 2> /dev/null | sed -e ‘/^[^*]/d’ -e ‘s/* \(.*\)/\1/’) 

         echo $branch (parse_git_dirty)     


function fish_prompt

         if test -z (git branch —quiet 2>| awk ‘/fatal:/ {print “no 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)            


            printf ‘%s@%s %s%s%s $ ’  (whoami) (hostname|cut -d . -f 1) (set_color $fish_color_cwd) (prompt_pwd) (set_color normal)



[1] Actually the best customization is changing the maximum size and count of the .bash_history file to be really big so that I can keep a lifetime of shell work.