Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@nh2
Forked from emcmanus/gist:2894558
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nh2/1e7e05a2b9f2ea229f23 to your computer and use it in GitHub Desktop.
Save nh2/1e7e05a2b9f2ea229f23 to your computer and use it in GitHub Desktop.
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
Copy link
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