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

209 lines
6.8 KiB
Fish
Raw Normal View History

2014-07-31 16:31:47 +08:00
function __budspencer_is_git_ahead_or_behind -d "Check if there are unpulled or unpushed commits"
echo (command git rev-list --count --left-right "HEAD...@{upstream}" ^/dev/null | sed 's/[[:space:]+]/\\x1e/g')
2014-07-26 14:09:31 +08:00
end
2014-07-31 16:31:47 +08:00
function __budspencer_git_status -d "Check git status"
set -l added 0
set -l deleted 0
set -l modified 0
set -l renamed 0
set -l unmerged 0
set -l untracked 0
set -l git_status (command git status --porcelain ^/dev/null)
for i in (seq 1 (count $git_status))
echo $git_status[$i] | egrep "^[ACDMT][\ MT]\ |^[ACMT]D\ " > /dev/null; and set added (math $added+1)
echo $git_status[$i] | egrep "^[\ ACMRT]D\ " > /dev/null; and set deleted (math $deleted+1)
echo $git_status[$i] | egrep "^.[MT]\ " > /dev/null; and set modified (math $modified+1)
echo $git_status[$i] | egrep "^R.\ " > /dev/null; and set renamed (math $renamed+1)
echo $git_status[$i] | egrep "^AA\ |^DD\ |^U.\ |^.U\ " > /dev/null; and set unmerged (math $unmerged+1)
echo $git_status[$i] | egrep "^\?\?\ " > /dev/null; and set untracked (math $untracked+1)
end
printf '%s\x1e%s\x1e%s\x1e%s\x1e%s\x1e%s' $added $deleted $modified $renamed $unmerged $untracked
2014-07-26 14:09:31 +08:00
end
function __budspencer_is_git_stashed -d "Check if there are stashed commits"
2014-07-31 16:31:47 +08:00
echo (command git stash list ^/dev/null | wc -l | awk '{print $1}')
2014-07-26 14:09:31 +08:00
end
set git_style "symbols"
function fish_git_toggle_cm --description "Toggles style of git segment, press ,, in NORMAL mode"
if test $git_style = "symbols"
2014-08-03 18:18:10 +08:00
set git_style "counts"
else
set git_style "symbols"
end
commandline -f repaint
end
bind -M default ',,' fish_git_toggle_cm
2014-07-26 14:09:31 +08:00
if set -q -x $PWDSTYLE
set -x PWDSTYLE short long none
end
set pwd_style $PWDSTYLE[1]
function fish_pwd_toggle_cm --description "Toggles style of pwd segment, press space bar in NORMAL mode"
for i in (seq 1 (count $PWDSTYLE))
if test $PWDSTYLE[$i] = $pwd_style
set pwd_style $PWDSTYLE[(math $i%(count $PWDSTYLE)+1)]
commandline -f repaint
break
end
end
end
bind -M default ' ' fish_pwd_toggle_cm
function fish_cmd_duration_cm -d "Displays the elapsed time of last command"
if test (count $CMD_DURATION) -gt 0
set -l duration (echo $CMD_DURATION | tr -d '[[:space:]]' | sed 's|\.[[:digit:]]*||')
if test $last_status -ne 0
2014-08-03 18:18:10 +08:00
echo -n (set_color $budspencer_colors[3])""(set_color -b $budspencer_colors[3] $budspencer_colors[12])" "$duration
else
2014-08-03 18:18:10 +08:00
echo -n (set_color $budspencer_colors[3])""(set_color -b $budspencer_colors[3] $budspencer_colors[17])" "$duration
end
2014-07-26 14:09:31 +08:00
end
end
2014-07-31 18:01:15 +08:00
function fish_git_prompt_cm --description "Displays the git symbols"
set -l git_prompt ""
2014-07-31 16:31:47 +08:00
set -l is_repo (command git rev-parse --is-inside-work-tree ^/dev/null)
2014-08-03 18:18:10 +08:00
if test $is_repo="true"
2014-07-31 18:01:15 +08:00
2014-07-31 16:31:47 +08:00
set -l git_ahead_behind (__budspencer_is_git_ahead_or_behind)
2014-08-04 00:50:09 +08:00
if test (count $git_ahead_behind) -eq 2
if test $git_ahead_behind[1] -gt 0
if test $git_style = "symbols"
set git_prompt (set_color -o $budspencer_colors[10])" ↑"
else
set git_prompt (set_color -o $budspencer_colors[10])" "$git_ahead_behind[1]
end
2014-07-31 18:01:15 +08:00
end
2014-08-03 18:18:10 +08:00
2014-08-04 00:50:09 +08:00
if test $git_ahead_behind[2] -gt 0
if test $git_style = "symbols"
set git_prompt $git_prompt(set_color -o $budspencer_colors[10])" ↓"
else
set git_prompt $git_prompt(set_color -o $budspencer_colors[10])" "$git_ahead_behind[2]
end
2014-07-31 18:01:15 +08:00
end
2014-07-31 16:31:47 +08:00
end
2014-08-03 18:18:10 +08:00
2014-07-31 16:31:47 +08:00
set -l git_status (__budspencer_git_status)
if test $git_status[1] -gt 0
2014-07-31 18:01:15 +08:00
if test $git_style = "symbols"
2014-08-03 18:18:10 +08:00
set git_prompt $git_prompt(set_color -o $budspencer_colors[17])" +"
2014-07-31 18:01:15 +08:00
else
2014-08-03 18:18:10 +08:00
set git_prompt $git_prompt(set_color -o $budspencer_colors[17])" "$git_status[1]
2014-07-31 18:01:15 +08:00
end
2014-07-31 16:31:47 +08:00
end
2014-07-26 14:09:31 +08:00
2014-07-31 16:31:47 +08:00
if test $git_status[2] -gt 0
2014-07-31 18:01:15 +08:00
if test $git_style = "symbols"
2014-08-03 18:18:10 +08:00
set git_prompt $git_prompt(set_color -o $budspencer_colors[12])" "
2014-07-31 18:01:15 +08:00
else
2014-08-03 18:18:10 +08:00
set git_prompt $git_prompt(set_color -o $budspencer_colors[12])" "$git_status[2]
2014-07-31 18:01:15 +08:00
end
2014-07-31 16:31:47 +08:00
end
2014-07-26 14:09:31 +08:00
2014-07-31 16:31:47 +08:00
if test $git_status[3] -gt 0
2014-07-31 18:01:15 +08:00
if test $git_style = "symbols"
2014-08-03 18:18:10 +08:00
set git_prompt $git_prompt(set_color -o $budspencer_colors[15])" ✱"
2014-07-31 18:01:15 +08:00
else
2014-08-03 18:18:10 +08:00
set git_prompt $git_prompt(set_color -o $budspencer_colors[15])" "$git_status[3]
2014-07-31 18:01:15 +08:00
end
2014-07-31 16:31:47 +08:00
end
2014-07-26 14:09:31 +08:00
2014-07-31 16:31:47 +08:00
if test $git_status[4] -gt 0
2014-07-31 18:01:15 +08:00
if test $git_style = "symbols"
2014-08-03 18:18:10 +08:00
set git_prompt $git_prompt(set_color -o $budspencer_colors[13])" →"
2014-07-31 18:01:15 +08:00
else
2014-08-03 18:18:10 +08:00
set git_prompt $git_prompt(set_color -o $budspencer_colors[13])" "$git_status[4]
2014-07-31 18:01:15 +08:00
end
2014-07-31 16:31:47 +08:00
end
2014-07-26 14:09:31 +08:00
2014-07-31 16:31:47 +08:00
if test $git_status[5] -gt 0
2014-07-31 18:01:15 +08:00
if test $git_style = "symbols"
2014-08-03 18:18:10 +08:00
set git_prompt $git_prompt(set_color -o $budspencer_colors[14])" ═"
2014-07-31 18:01:15 +08:00
else
2014-08-03 18:18:10 +08:00
set git_prompt $git_prompt(set_color -o $budspencer_colors[14])" "$git_status[5]
2014-07-31 18:01:15 +08:00
end
2014-07-31 16:31:47 +08:00
end
2014-07-26 14:09:31 +08:00
2014-07-31 16:31:47 +08:00
if test $git_status[6] -gt 0
2014-07-31 18:01:15 +08:00
if test $git_style = "symbols"
2014-08-03 18:18:10 +08:00
set git_prompt $git_prompt(set_color -o $budspencer_colors[9])" ●"
2014-07-31 18:01:15 +08:00
else
2014-08-03 18:18:10 +08:00
set git_prompt $git_prompt(set_color -o $budspencer_colors[9])" "$git_status[6]
2014-07-31 18:01:15 +08:00
end
2014-07-31 16:31:47 +08:00
end
2014-07-31 18:01:15 +08:00
set -l git_stashed (__budspencer_is_git_stashed)
if test git_stashed -gt 0
if test $git_style = "symbols"
2014-08-03 18:18:10 +08:00
set git_prompt $git_prompt(set_color -o $budspencer_colors[16])" ✭"
2014-07-31 18:01:15 +08:00
else
2014-08-03 18:18:10 +08:00
set git_prompt $git_prompt(set_color -o $budspencer_colors[16])" "$git_stashed
2014-07-31 18:01:15 +08:00
end
2014-07-31 16:31:47 +08:00
end
2014-08-04 00:50:09 +08:00
echo -n $git_prompt
2014-07-31 18:01:15 +08:00
2014-07-26 14:09:31 +08:00
end
2014-07-31 18:01:15 +08:00
end
2014-07-26 14:09:31 +08:00
function fish_pwd_prompt_cm --description "Displays the present working directory"
set -l user_host " "
if test (count $SSH_CLIENT) -gt 0
set user_host " "$USER"@"(hostname)
if test $pwd_style != "none"
set user_host $user_host":"
end
2014-08-03 18:18:10 +08:00
end
switch $fish_bind_mode
case default
2014-08-03 18:18:10 +08:00
set_color $budspencer_colors[15]
echo -n ""
set_color normal
2014-08-03 18:18:10 +08:00
set_color -b $budspencer_colors[15] $budspencer_colors[1]
case insert
2014-08-03 18:18:10 +08:00
set_color $budspencer_colors[10]
echo -n ""
set_color normal
2014-08-03 18:18:10 +08:00
set_color -b $budspencer_colors[10] $budspencer_colors[1]
case visual
2014-08-03 18:18:10 +08:00
set_color $budspencer_colors[13]
echo -n ""
set_color normal
2014-08-03 18:18:10 +08:00
set_color -b $budspencer_colors[13] $budspencer_colors[1]
end
switch $pwd_style
case none
echo -n $user_host' '
case short
echo -n $user_host(prompt_pwd)' '
case long
echo -n $user_host$PWD' ' # | sed "s|$HOME|~|"
end
set_color normal
end
2014-07-31 18:01:15 +08:00
function fish_right_prompt -d "Write out the right prompt of the budspencer theme"
2014-08-03 18:18:10 +08:00
2014-07-31 18:01:15 +08:00
# Segments
# command duration
set ps_duration (fish_cmd_duration_cm)
2014-07-31 18:01:15 +08:00
# git
set ps_git (fish_git_prompt_cm)
2014-07-26 14:09:31 +08:00
if test -n "$ps_git"
2014-08-03 18:18:10 +08:00
set ps_git (set_color $budspencer_colors[4])""(set_color -b $budspencer_colors[4])""$ps_git
2014-07-26 14:09:31 +08:00
end
2014-08-03 18:18:10 +08:00
# pwd
2014-07-26 14:09:31 +08:00
set -l ps_pwd ""
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_pwd (fish_pwd_prompt_cm)
end
echo -n $ps_duration $ps_git $ps_pwd
2014-07-26 14:09:31 +08:00
set_color normal
end