Skip to content

Instantly share code, notes, and snippets.

@nh2 nh2/fish_git_ps1.fish forked from emcmanus/gist:2894558
Last active Aug 29, 2015

Embed
What would you like to do?
Functoin for the fish shell that gets the current git branch + if a merge/rebase etc. is in progress (port of GIt's __git_ps1); adapted to work for newer versions of fish (e.g. 2.2.0)
# Functoin for the fish shell that gets the current git branch + if a merge/rebase etc. is in progress (port of GIt's __git_ps1); adapted to work for newer versions of fish (e.g. 2.2.0)
function __git_ps1
set -l g (git rev-parse --git-dir ^/dev/null)
if [ -n "$g" ]
set -l r ""
set -l b ""
if [ -d "$g/rebase" ]
if [ -f "$g/rebase/rebasing" ]
set r "|REBASE"
else if [ -f "$g/rebase/applying" ]
set r "|AM"
else
set r "|AM/REBASE"
end
set b (git symbolic-ref HEAD ^/dev/null)
else if [ -f "$g/rebase-merge/interactive" ]
set r "|REBASE-i"
set b (cat "$g/rebase-merge/head-name")
else if [ -d "$g/rebase-merge" ]
set r "|REBASE-m"
set b (cat "$g/rebase-merge/head-name")
else if [ -f "$g/MERGE_HEAD" ]
set r "|MERGING"
set b (git symbolic-ref HEAD ^/dev/null)
else
if [ -f "$g/BISECT_LOG" ]
set r "|BISECTING"
end
set b (git symbolic-ref HEAD ^/dev/null)
if [ -z $b ]
set b (git describe --exact-match HEAD ^/dev/null)
if [ -z $b ]
set b (cut -c1-7 "$g/HEAD")
set b "$b..."
end
end
end
if not test $argv
set argv " (%s)"
end
set b (echo $b | sed -e 's|^refs/heads/||')
printf $argv "$b$r" ^/dev/null
end
end
@nh2

This comment has been minimized.

Copy link
Owner Author

nh2 commented Jul 18, 2015

Changes I had to make over these two:

in order for it to work with my newer fish 2.2.0:

  • switched elseifto newer else if syntax (see here)
  • switched $g/../.dotest to $g/rebase and $g/.dotest-merge to $g/rebase-merge (see here)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.