Skip to content

Instantly share code, notes, and snippets.

@RowanFeely
Created April 19, 2020 20:02
Show Gist options
  • Save RowanFeely/e60f07617eca635507c51e1fc6693076 to your computer and use it in GitHub Desktop.
Save RowanFeely/e60f07617eca635507c51e1fc6693076 to your computer and use it in GitHub Desktop.
# A lambda (λ) prompt.
#
# Yellow and red depending on exit status.
# Underlined if git status is dirty.
# Uppercase (Λ) if ahead of the remote.
#left hand side prompt
function fish_prompt
if is_status_okay
set_color yellow
else
set_color red
end
if is_git_dirty
set_color --underline
end
if is_git_ahead
echo -n 'Λ'
else
echo -n 'λ'
set_color normal
end
set_color normal
echo -n ' '
end
function fish_right_prompt
set_color black
echo "░▒▓█"
set_color brcyan --background black
# Show directory name
echo -n (dirname (prompt_pwd))/
# show directory in red if not writeable, otherwise highlight the basename of directory
if not [ -w (pwd) ]
set_color red
else
set_color cyan
end
echo -n (basename (prompt_pwd))
echo -n " "
# Show length of command execution in seconds
if test $CMD_DURATION
set duration (echo "$CMD_DURATION 1000" | awk '{printf "%.3fs", $1 / $2}')
set_color yellow --background black
echo -n "Ω$duration"
set_color normal
end
end
#right hand side prompt
# function fish_right_prompt
# set_color brblack
# echo -n (hostname | cut -d . -f 1)
# echo -n '|'
# set_color $fish_color_cwd
# echo -n (prompt_pwd)
# set_color normal
# echo -n ' '
# if is_git
# set_color magenta
# echo -n (git_branch)' '
# set_color normal
# end
#end
#git functions
function git_branch
if is_git
echo (git rev-parse --abbrev-ref HEAD 2> /dev/null)
end
end
function is_git
git symbolic-ref HEAD >/dev/null 2>&1
end
function is_git_ahead
set -l revs (git rev-list origin/(git_branch)..HEAD ^ /dev/null)
[ "$revs" != "" ]
end
function is_git_dirty
is_git
and [ (git status | tail -n1) != "nothing to commit, working tree clean" ]
end
function is_status_okay
[ $status = 0 ]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment