Skip to content

Instantly share code, notes, and snippets.

@kristerkari
Last active December 25, 2017 11:35
Show Gist options
  • Save kristerkari/5626386 to your computer and use it in GitHub Desktop.
Save kristerkari/5626386 to your computer and use it in GitHub Desktop.
Fish config/prompt
# Port of the Bash version bundled with git
# Bodaniel Jeanes
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
set -x EDITOR "subl"
set -x VISUAL $EDITOR
set -x GIT_EDITOR $EDITOR
set -x CLICOLOR 1
set -U BROWSER "open -a Chrome"
set fish_color_git_branch green
set fish_color_cwd blue
set fish_color_uneditable_cwd red
function fish_prompt --description 'Write out the prompt'
set -l last_status $status
printf '%s%s%s ' (set_color green) (whoami) (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 yellow)
end
printf '%s ' (set_color -o $fish_color_cwd) (set_color normal)
if not test $last_status -eq 0
set_color $fish_color_error
end
printf '\n↳ ' (set_color normal)
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment