Skip to content

Instantly share code, notes, and snippets.

@eakst7
Forked from britishtea/fish_right_prompt.fish
Last active October 17, 2023 19:42
Show Gist options
  • Save eakst7/cbc36e68c9f7270ab9bb866f2d3580bd to your computer and use it in GitHub Desktop.
Save eakst7/cbc36e68c9f7270ab9bb866f2d3580bd to your computer and use it in GitHub Desktop.
My right prompt for the fish shell.
function fish_right_prompt -d "Write out the right prompt"
# Stolen and adapted from: https://gist.github.com/britishtea/39ad478fa5180e1432a2
set -l exit_code $status
set -l is_git_repository (git rev-parse --is-inside-work-tree 2>/dev/null)
set_color black
# Print a red dot for failed commands.
if test $exit_code -ne 0
set_color red
echo -n "• "
set_color black
end
# Print coloured arrows when git push (up) and / or git pull (down) can be run.
#
# Red means the local branch and the upstream branch have diverted.
# Yellow means there are more than 3 commits to push or pull.
if test "true" = "$is_git_repository"
git rev-parse --abbrev-ref '@{upstream}' >/dev/null 2>&1; and set -l has_upstream
if set -q has_upstream
set -l commit_counts (git rev-list --left-right --count 'HEAD...@{upstream}' 2>/dev/null)
set -l commits_to_push (echo $commit_counts | cut -f 1 2>/dev/null)
set -l commits_to_pull (echo $commit_counts | cut -f 2 2>/dev/null)
if test $commits_to_push != 0
if test $commits_to_pull -ne 0
set_color red
else if test $commits_to_push -gt 3
set_color yellow
else
set_color green
end
echo -n "⇡ "
end
if test $commits_to_pull != 0
if test $commits_to_push -ne 0
set_color red
else if test $commits_to_pull -gt 3
set_color yellow
else
set_color green
end
echo -n "⇣ "
end
set_color black
end
# Print a "stack symbol" if there are stashed changes.
if test (git stash list | wc -l) -gt 0
echo -n "☰ "
end
end
# Print the username when the user has been changed.
if test $USER != $LOGNAME
echo -n "$USER@"
end
# Print the current git branch name or shortened commit hash in colour.
#
# Green means the working directory is clean.
# Yellow means all changed files have been staged.
# Red means there are changed files that are not yet staged.
#
# Untracked files are ignored.
if test "true" = "$is_git_repository"
echo -n ":"
set -l branch (git symbolic-ref --short HEAD 2>/dev/null; or git show-ref --head -s --abbrev | head -n1 2>/dev/null)
git diff-files --quiet --ignore-submodules 2>/dev/null; or set -l has_unstaged_files
git diff-index --quiet --ignore-submodules --cached HEAD 2>/dev/null; or set -l has_staged_files
if set -q has_unstaged_files
set_color red
else if set -q has_staged_files
set_color yellow
else
set_color green
end
echo -n $branch
set_color black
end
set_color normal
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment