This is actually already implemented in fish natively under the name
__fish_git_prompt
. When I set out to make this port I was not aware of it,
as googling fish __git_ps1
returned the attempts mentioned below.
If you got here on a similar path you probably want to use the builtin version.
Seriously, it has more features and is way better written.
This is a port of the __git_ps1
command for bash/zsh that is part of git.
The work was inspired by earlier attempts at making such a port, the
latest of which can be found
here.