Git Information in Fish Shell’s Prompt

After toying around with Zsh for a while I stumbled upon Fish or more precisely Ridiculous Fish which is a fork of the original Fish Shell.

Since Fish does not have a configuration framework like oh-my-zsh you have to setup your prompt with additional Git information yourself. I consider this an advantage though as you can't just take a bunch of configuration files from somewhere without having an idea what they actually do.

It took me a while to find this part of the Fish source code which documents this functionality quite well. An example which you can put into ~/.config/fish/config.fish follows below:

set normal (set_color normal)
set magenta (set_color magenta)
set yellow (set_color yellow)
set green (set_color green)
set red (set_color red)
set gray (set_color -o black)

# Fish git prompt
set __fish_git_prompt_showdirtystate 'yes'
set __fish_git_prompt_showstashstate 'yes'
set __fish_git_prompt_showuntrackedfiles 'yes'
set __fish_git_prompt_showupstream 'yes'
set __fish_git_prompt_color_branch yellow
set __fish_git_prompt_color_upstream_ahead green
set __fish_git_prompt_color_upstream_behind red

# Status Chars
set __fish_git_prompt_char_dirtystate '⚡'
set __fish_git_prompt_char_stagedstate '→'
set __fish_git_prompt_char_untrackedfiles '☡'
set __fish_git_prompt_char_stashstate '↩'
set __fish_git_prompt_char_upstream_ahead '+'
set __fish_git_prompt_char_upstream_behind '-'


function fish_prompt
  set last_status $status

  set_color $fish_color_cwd
  printf '%s' (prompt_pwd)
  set_color normal

  printf '%s ' (__fish_git_prompt)

  set_color normal
end
@martinklepsch, December 2012

Other Posts

  1. Just-in-Time Script Loading With React And ClojureScriptNovember 2016
  2. Props, Children & Component Lifecycle in ReagentMay 2016
  3. Om/Next Reading ListNovember 2015
  4. Parameterizing ClojureScript BuildsAugust 2015
  5. ClojureBridge BerlinJuly 2015
  6. Managing Local and Project-wide Development Parameters in LeiningenJune 2015
  7. Formal Methods at AmazonApril 2015
  8. (lisp keymap)February 2015
  9. CLJSJS - Use Javascript Libraries in Clojurescript With EaseJanuary 2015
  10. Why Boot is Relevant For The Clojure EcosystemNovember 2014
  11. S3-Beam — Direct Upload to S3 with Clojure & ClojurescriptOctober 2014
  12. Patalyze — An Experiment Exploring Publicly Available Patent DataOctober 2014
  13. Running a Clojure Uberjar inside DockerSeptember 2014
  14. Using core.async and Transducers to upload files from the browser to S3September 2014
  15. Emacs & VimJuly 2014
  16. Heroku-like Deployment With Dokku And DigitalOceanMarch 2014
  17. Woodworking MasterclassesFebruary 2014
  18. Early Adopters And Inverted Social ProofFebruary 2014
  19. Living SmallFebruary 2014
  20. Sending You a TelegramJanuary 2014
  21. Running a Marathon, Or NotJanuary 2014
  22. Code SimplicityJanuary 2014
  23. What do we need to know?December 2013
  24. Sculley's DiseaseDecember 2013
  25. A Resurrection PostDecember 2013
  26. A Trip To The USSeptember 2013
  27. Analytics DataApril 2013
  28. Asynchronous CommunicationApril 2013
  29. From Zero to Marathon in Six MonthtsMarch 2013
  30. When We Build StuffAugust 2012
  31. Models, Operations, Views and EventsJuly 2012
  32. The Twelve Factor AppJune 2012
  33. Paris And BackMay 2012
  34. A Friend Is Looking For A Summer InternshipMay 2012
  35. Kandan Team ChatMay 2012
  36. Startups, This Is How Design WorksMarch 2012
  37. Entypo Icon SetMarch 2012
  38. Hosting A Static Site On Amazon S3February 2012
  39. Exim4 Fix Wrongly Decoded Mail SubjectJanuary 2012