oh-my-fish/themes/budspencer/fish_prompt.fish

128 lines
4.2 KiB
Fish
Raw Normal View History

###############################################################################
#
# prompt theme name: budspencer
#
# description: a sophisticated airline/powerline theme
#
# author: Joseph Tannhuber
#
###############################################################################
2014-07-26 14:09:31 +08:00
2014-08-03 18:18:10 +08:00
###############################################################################
# Color definitions
###############################################################################
set -g budspencer_colors 000000 083743 445659 fdf6e3 b58900 cb4b16 dc121f af005f 6c71c4 268bd2 2aa198 859900
2014-08-03 18:18:10 +08:00
###############################################################################
2014-07-26 14:09:31 +08:00
# Utils
2014-08-03 18:18:10 +08:00
###############################################################################
2014-07-26 14:09:31 +08:00
set -g __budspencer_display_rprompt 1
function __budspencer_git_branch_name -d "Return the current branch name"
2014-08-04 04:29:33 +08:00
set -l branch (git symbolic-ref HEAD ^/dev/null | sed -e 's|^refs/heads/||')
if test (count $branch) -eq 0
set -l position (git describe --contains --all HEAD ^/dev/null)
if test (count $position) -eq 0
2014-08-04 17:06:43 +08:00
set -l commit (git rev-parse HEAD ^/dev/null | sed -r 's|(^.{7}).*|\1|')
echo -n (set_color -b $budspencer_colors[11])""(set_color $budspencer_colors[1])" ➦ "$commit" "(set_color $budspencer_colors[11])
else
echo -n (set_color -b $budspencer_colors[9])""(set_color $budspencer_colors[1])"  "$position" "(set_color $budspencer_colors[9])
end
2014-08-04 04:29:33 +08:00
else
echo -n (set_color -b $budspencer_colors[3])""(set_color $budspencer_colors[1])"  "$branch" "(set_color $budspencer_colors[3])
2014-08-04 04:29:33 +08:00
end
2014-07-26 14:09:31 +08:00
end
function fish_vi_prompt_cm --description "Displays the current mode"
switch $fish_bind_mode
case default
2014-08-03 18:18:10 +08:00
set_color -b $budspencer_colors[10] $budspencer_colors[1]
2014-08-04 00:12:24 +08:00
echo -en "\033]12;#$budspencer_colors[10]\007"
echo -n " NORMAL "
2014-08-03 18:18:10 +08:00
set_color -b $budspencer_colors[1] $budspencer_colors[10]
case insert
set_color -b $budspencer_colors[5] $budspencer_colors[1]
echo -en "\033]12;#$budspencer_colors[5]\007"
echo -n " INSERT "
set_color -b $budspencer_colors[1] $budspencer_colors[5]
2014-07-26 14:09:31 +08:00
case visual
set_color -b $budspencer_colors[8] $budspencer_colors[1]
echo -en "\033]12;#$budspencer_colors[8]\007"
2014-07-26 14:09:31 +08:00
echo -n " VISUAL "
set_color -b $budspencer_colors[1] $budspencer_colors[8]
2014-07-26 14:09:31 +08:00
end
end
function fish_prompt_symbols --description "Display symbols"
set_color -b $budspencer_colors[2]
2014-08-03 18:18:10 +08:00
echo -n ""
2014-07-26 14:09:31 +08:00
# indicator for vim parent process
if set -q -x VIM
set_color -o $budspencer_colors[9]
2014-08-03 18:18:10 +08:00
echo -n " V"
2014-07-26 14:09:31 +08:00
end
# indicator for ranger parent process
if set -q -x RANGER_LEVEL
set_color -o $budspencer_colors[9]
2014-08-03 18:18:10 +08:00
echo -n " R"
2014-07-26 14:09:31 +08:00
end
# background job indicator
if [ (jobs | wc -l) -gt 0 ]
set_color -o $budspencer_colors[11]
2014-08-03 18:18:10 +08:00
echo -n " ⚙"
2014-07-26 14:09:31 +08:00
end
# write protection indicator
if [ ! -w . ]
set_color -o $budspencer_colors[6]
2014-08-03 18:18:10 +08:00
echo -n " "
2014-07-26 14:09:31 +08:00
end
# status indicator
if [ $last_status -eq 0 ]
set_color -o $budspencer_colors[12]
2014-07-26 14:09:31 +08:00
echo -n " ✔"
else
set_color -o $budspencer_colors[7]
2014-07-26 14:09:31 +08:00
echo -n " ✘"
end
# superuser indicator
if [ $USER = "root" ]
set_color -o $budspencer_colors[6]
2014-08-03 18:18:10 +08:00
echo -n " ⚡"
2014-07-26 14:09:31 +08:00
end
echo -n " "
set_color -b normal $budspencer_colors[2]
2014-07-26 14:09:31 +08:00
end
2014-08-03 18:18:10 +08:00
###############################################################################
# Prompt
2014-08-03 18:18:10 +08:00
###############################################################################
2014-07-26 14:09:31 +08:00
function fish_prompt -d "Write out the left prompt of the budspencer theme"
set -g last_status $status
set -l basedir_name (basename (prompt_pwd))
#############################################################################
2014-07-26 14:09:31 +08:00
# Segments
#############################################################################
2014-08-03 18:18:10 +08:00
2014-07-26 14:09:31 +08:00
# vi mode
set -l ps_vi ""
2014-08-03 18:18:10 +08:00
if test "$fish_key_bindings" = "fish_vi_key_bindings" -o "$fish_key_bindings" = "my_fish_key_bindings"
2014-07-26 14:09:31 +08:00
set ps_vi (fish_vi_prompt_cm)
end
# git
set -l ps_git ""
set -l git_branch_name (__budspencer_git_branch_name)
if test -n "$git_branch_name"
2014-08-04 04:29:33 +08:00
set ps_git $git_branch_name
2014-07-26 14:09:31 +08:00
end
# symbols
2014-07-26 14:09:31 +08:00
set -l ps_symbols (fish_prompt_symbols)
# left prompt
2014-07-26 14:09:31 +08:00
echo -n -s $ps_vi $ps_git $ps_symbols '' ' '
end