Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Git Status in FishFish Prompt - Fish port of __git_ps1
# Port of __git_ps1 for Fish shell (tested with FishFish)
#--------------------------------------------------------------------------------------------------
# https://github.com/bjeanes/dot-files/tree/294254ce2f064bbfc586e98107da1ed510898ffd/fish/functions
# via @bjeanes - https://github.com/bjeanes
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/../.dotest" ]
if [ -f "$g/../.dotest/rebasing" ]
set r "|REBASE"
elseif [ -f "$g/../.dotest/applying" ]
set r "|AM"
else
set r "|AM/REBASE"
end
set b (git symbolic-ref HEAD ^/dev/null)
elseif [ -f "$g/.dotest-merge/interactive" ]
set r "|REBASE-i"
set b (cat "$g/.dotest-merge/head-name")
elseif [ -d "$g/.dotest-merge" ]
set r "|REBASE-m"
set b (cat "$g/.dotest-merge/head-name")
elseif [ -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
function git_dirty
if not is_git_repo
return 1
end
not git diff HEAD --quiet ^/dev/null
end
function is_git_repo
git status >/dev/null ^/dev/null
not test $status -eq 128
end
function fish_prompt --description 'Write out the prompt'
printf '%s%s@%s%s ' (set_color green) (whoami) (hostname|cut -d . -f 1) (set_color normal)
# Write the process working directory
if test -w "."
printf '%s%s' (set_color -o $fish_color_cwd) (prompt_pwd)
else
printf '%s%s' (set_color -o $fish_color_uneditable_cwd) (prompt_pwd)
end
printf '%s%s ' (set_color red) (__git_ps1)
if git_dirty
printf '%s✮ ' (set_color -o green)
end
printf '%s$%s ' (set_color -o $fish_color_cwd) (set_color normal)
printf '%s> ' (set_color normal)
end
@nh2

This comment has been minimized.

Copy link

nh2 commented Jul 18, 2015

I made an updated version of the __git_ps1 function that works with fish 2 here: https://gist.github.com/nh2/1e7e05a2b9f2ea229f23

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.