Commit fce4cadd authored by Joseph Tannhuber's avatar Joseph Tannhuber Committed by Bruno Pinto

Budspencer theme improvements

- Bookmarks and command/directory history functions implemented
- Function to edit commandline with $EDITOR
- Faster git parser
parent 01adb417
...@@ -171,7 +171,8 @@ It makes the commandline as powerful as your editor. If `$EDITOR` is not set, ...@@ -171,7 +171,8 @@ It makes the commandline as powerful as your editor. If `$EDITOR` is not set,
vi is used. vi is used.
The following shortcut needs vi mode: The following shortcut needs vi mode:
- Type `.` in NORMAL mode to edit commandline in editor. - Type `.` in NORMAL mode or `\cv` in NORMAL/INSERT mode to edit commandline in
editor.
## Sessions ## Sessions
......
...@@ -27,8 +27,8 @@ ...@@ -27,8 +27,8 @@
set -U budspencer_night 000000 083743 445659 fdf6e3 b58900 cb4b16 dc121f af005f 6c71c4 268bd2 2aa198 859900 set -U budspencer_night 000000 083743 445659 fdf6e3 b58900 cb4b16 dc121f af005f 6c71c4 268bd2 2aa198 859900
set -U budspencer_day 000000 333333 666666 ffffff ffff00 ff6600 ff0000 ff0033 3300ff 00aaff 00ffff 00ff00 set -U budspencer_day 000000 333333 666666 ffffff ffff00 ff6600 ff0000 ff0033 3300ff 00aaff 00ffff 00ff00
if not set -q budspencer_colors if not set -q budspencer_colors
# Values are: black dark_gray light_gray white yellow orange red magenta violet blue cyan green # Values are: black dark_gray light_gray white yellow orange red magenta violet blue cyan green
set -U budspencer_colors $budspencer_night set -U budspencer_colors $budspencer_night
end end
# Cursor color changes according to vi-mode # Cursor color changes according to vi-mode
...@@ -38,7 +38,7 @@ set -U budspencer_cursors "\033]12;#$budspencer_colors[10]\007" "\033]12;#$budsp ...@@ -38,7 +38,7 @@ set -U budspencer_cursors "\033]12;#$budspencer_colors[10]\007" "\033]12;#$budsp
# Some terminals cannot change the cursor color # Some terminals cannot change the cursor color
set -l unsupported_terminals 'fbterm' 'st' 'linux' 'screen' set -l unsupported_terminals 'fbterm' 'st' 'linux' 'screen'
if contains $TERM $unsupported_terminals if contains $TERM $unsupported_terminals
set budspencer_cursors '' '' '' '' set budspencer_cursors '' '' '' ''
end end
############################################################################### ###############################################################################
...@@ -49,54 +49,54 @@ end ...@@ -49,54 +49,54 @@ end
# => Help # => Help
######### #########
function budspencer_help -d 'Show helpfile' function budspencer_help -d 'Show helpfile'
set -l readme_file "$fish_path/themes/budspencer/README.md" set -l readme_file "$fish_path/themes/budspencer/README.md"
if set -q PAGER if set -q PAGER
if [ -e $readme_file ] if [ -e $readme_file ]
eval $PAGER $readme_file eval $PAGER $readme_file
else else
set_color $fish_color_error[1] set_color $fish_color_error[1]
echo "$readme_file wasn't found." echo "$readme_file wasn't found."
end end
else else
open $readme_file open $readme_file
end end
end end
################ ################
# => Environment # => Environment
################ ################
function day -d "Set color palette for bright environment." function day -d "Set color palette for bright environment."
set budspencer_colors $budspencer_day set budspencer_colors $budspencer_day
set budspencer_cursors "\033]12;#$budspencer_colors[10]\007" "\033]12;#$budspencer_colors[5]\007" "\033]12;#$budspencer_colors[8]\007" "\033]12;#$budspencer_colors[9]\007" set budspencer_cursors "\033]12;#$budspencer_colors[10]\007" "\033]12;#$budspencer_colors[5]\007" "\033]12;#$budspencer_colors[8]\007" "\033]12;#$budspencer_colors[9]\007"
end end
function night -d "Set color palette for dark environment." function night -d "Set color palette for dark environment."
set budspencer_colors $budspencer_night set budspencer_colors $budspencer_night
set budspencer_cursors "\033]12;#$budspencer_colors[10]\007" "\033]12;#$budspencer_colors[5]\007" "\033]12;#$budspencer_colors[8]\007" "\033]12;#$budspencer_colors[9]\007" set budspencer_cursors "\033]12;#$budspencer_colors[10]\007" "\033]12;#$budspencer_colors[5]\007" "\033]12;#$budspencer_colors[8]\007" "\033]12;#$budspencer_colors[9]\007"
end end
################# #################
# => Window title # => Window title
################# #################
function wt -d 'Set window title' function wt -d 'Set window title'
set -g window_title $argv set -g window_title $argv
function fish_title function fish_title
echo -n $window_title echo -n $window_title
end end
end end
#################### ####################
# => Welcome message # => Welcome message
#################### ####################
function fish_greeting -d 'Show greeting in login shell.' function fish_greeting -d 'Show greeting in login shell.'
if not set -q budspencer_nogreeting if not set -q budspencer_nogreeting
if begin if begin
not set -q -x LOGIN not set -q -x LOGIN
and not set -q -x RANGER_LEVEL and not set -q -x RANGER_LEVEL
and not set -q -x VIM and not set -q -x VIM
end end
echo This is (set_color -b $budspencer_colors[2] $budspencer_colors[10])budspencer(set_color normal) theme for fish, a theme for the 70s. echo This is (set_color -b $budspencer_colors[2] $budspencer_colors[10])budspencer(set_color normal) theme for fish, a theme for the 70s.
echo Type (set_color -b $budspencer_colors[2] $budspencer_colors[6])»budspencer_help«(set_color normal) in order to see how you can speed up your workflow. echo Type (set_color -b $budspencer_colors[2] $budspencer_colors[6])»budspencer_help«(set_color normal) in order to see how you can speed up your workflow.
end end
end end
end end
...@@ -32,17 +32,19 @@ ...@@ -32,17 +32,19 @@
############################################################################### ###############################################################################
if [ $fish_key_bindings = 'fish_vi_key_bindings' ] if [ $fish_key_bindings = 'fish_vi_key_bindings' ]
bind '#' __budspencer_toggle_symbols bind '#' __budspencer_toggle_symbols
bind -M visual '#' __budspencer_toggle_symbols bind -M visual '#' __budspencer_toggle_symbols
bind ' ' __budspencer_toggle_pwd bind ' ' __budspencer_toggle_pwd
bind -M visual ' ' __budspencer_toggle_pwd bind -M visual ' ' __budspencer_toggle_pwd
bind L __budspencer_cd_next bind L __budspencer_cd_next
bind H __budspencer_cd_prev bind H __budspencer_cd_prev
bind m mark bind m mark
bind M unmark bind M unmark
bind . __budspencer_edit_comandline bind . __budspencer_edit_commandline
bind -M insert \n __budspencer_preexec bind \cv __budspencer_edit_commandline
bind \n __budspencer_preexec bind -M insert \cv __budspencer_edit_commandline
bind -M insert \n __budspencer_preexec
bind \n __budspencer_preexec
end end
############################################################################### ###############################################################################
...@@ -63,558 +65,566 @@ set -g budspencer_tmpfile '/tmp/'(echo %self)'_budspencer_edit.fish' ...@@ -63,558 +65,566 @@ set -g budspencer_tmpfile '/tmp/'(echo %self)'_budspencer_edit.fish'
# => Pre execute # => Pre execute
################ ################
function __budspencer_preexec -d 'Execute after hitting <Enter> before doing anything else' function __budspencer_preexec -d 'Execute after hitting <Enter> before doing anything else'
set -l cmd (commandline | sed 's|\s\+|\x1e|g') set -l cmd (commandline | sed 's|\s\+|\x1e|g')
if [ $_ = 'fish' ] if [ $_ = 'fish' ]
if [ -z $cmd[1] ] if [ -z $cmd[1] ]
set -e cmd[1] set -e cmd[1]
end end
if [ -z $cmd[1] ] if [ -z $cmd[1] ]
return return
end end
set -e budspencer_prompt_error[1] set -e budspencer_prompt_error[1]
if not type -q $cmd[1] if not type -q $cmd[1]
if [ -d $cmd[1] ] if [ -d $cmd[1] ]
set budspencer_prompt_error (cd $cmd[1] ^&1) set budspencer_prompt_error (cd $cmd[1] ^&1)
and commandline '' and commandline ''
commandline -f repaint commandline -f repaint
return return
end end
end end
switch $cmd[1] switch $cmd[1]
case 'c' case 'c'
if begin if begin
[ (count $cmd) -gt 1 ] [ (count $cmd) -gt 1 ]
and [ $cmd[2] -gt 0 ] and [ $cmd[2] -gt 0 ]
and [ $cmd[2] -lt $pcount ] and [ $cmd[2] -lt $pcount ]
end end
commandline $prompt_hist[$cmd[2]] commandline $prompt_hist[$cmd[2]]
echo $prompt_hist[$cmd[2]] | xsel echo $prompt_hist[$cmd[2]] | xsel
commandline -f repaint commandline -f repaint
return return
end end
case 'cd' case 'cd'
if [ (count $cmd) -le 2 ] if [ (count $cmd) -le 2 ]
set budspencer_prompt_error (eval $cmd ^&1) set budspencer_prompt_error (eval $cmd ^&1)
and commandline '' and commandline ''
if [ (count $budspencer_prompt_error) -gt 1 ] if [ (count $budspencer_prompt_error) -gt 1 ]
set budspencer_prompt_error $budspencer_prompt_error[1] set budspencer_prompt_error $budspencer_prompt_error[1]
end end
commandline -f repaint commandline -f repaint
return return
end end
case 'day' 'night' case 'day' 'night'
if [ (count $cmd) -eq 1 ] if [ (count $cmd) -eq 1 ]
eval $cmd eval $cmd
commandline '' commandline ''
commandline -f repaint commandline -f repaint
return return
end end
end end
end end
commandline -f execute commandline -f execute
end
#####################
# => Fish termination
#####################
function __budspencer_on_termination -s HUP -s INT -s QUIT -s TERM --on-process %self -d 'Execute when shell terminates'
set -l item (contains -i %self $budspencer_sessions_active_pid ^ /dev/null)
__budspencer_detach_session $item
end end
###################### ######################
# => Directory history # => Directory history
###################### ######################
function __budspencer_create_dir_hist -v PWD -d 'Create directory history without duplicates' function __budspencer_create_dir_hist -v PWD -d 'Create directory history without duplicates'
if [ $pwd_hist_lock = false ] if [ "$pwd_hist_lock" = false ]
if contains $PWD $$dir_hist if contains $PWD $$dir_hist
set -e $dir_hist[1][(contains -i $PWD $$dir_hist)] set -e $dir_hist[1][(contains -i $PWD $$dir_hist)]
end end
set $dir_hist $$dir_hist $PWD set $dir_hist $$dir_hist $PWD
set -g dir_hist_val (count $$dir_hist) set -g dir_hist_val (count $$dir_hist)
end end
end end
function __budspencer_cd_prev -d 'Change to previous directory, press H in NORMAL mode.' function __budspencer_cd_prev -d 'Change to previous directory, press H in NORMAL mode.'
if [ $dir_hist_val -gt 1 ] if [ $dir_hist_val -gt 1 ]
set dir_hist_val (expr $dir_hist_val - 1) set dir_hist_val (expr $dir_hist_val - 1)
set pwd_hist_lock true set pwd_hist_lock true
cd $$dir_hist[1][$dir_hist_val] cd $$dir_hist[1][$dir_hist_val]
commandline -f repaint commandline -f repaint
end end
end end
function __budspencer_cd_next -d 'Change to next directory, press L in NORMAL mode.' function __budspencer_cd_next -d 'Change to next directory, press L in NORMAL mode.'
if [ $dir_hist_val -lt (count $$dir_hist) ] if [ $dir_hist_val -lt (count $$dir_hist) ]
set dir_hist_val (expr $dir_hist_val + 1) set dir_hist_val (expr $dir_hist_val + 1)
set pwd_hist_lock true set pwd_hist_lock true
cd $$dir_hist[1][$dir_hist_val] cd $$dir_hist[1][$dir_hist_val]
commandline -f repaint commandline -f repaint
end end
end end
function d -d 'List directory history, jump to directory in list with d <number>' function d -d 'List directory history, jump to directory in list with d <number>'
set -l num_items (expr (count $$dir_hist) - 1) set -l num_items (expr (count $$dir_hist) - 1)
if [ $num_items -eq 0 ] if [ $num_items -eq 0 ]
set_color $fish_color_error[1] set_color $fish_color_error[1]
echo 'Directory history is empty. '(set_color normal)'It will be created automatically' echo 'Directory history is empty. '(set_color normal)'It will be created automatically'
return return
end end
for i in (seq $num_items) for i in (seq $num_items)
if [ (expr \( $num_items - $i \) \% 2) -eq 0 ] if [ (expr \( $num_items - $i \) \% 2) -eq 0 ]
set_color normal set_color normal
else else
set_color $budspencer_colors[4] set_color $budspencer_colors[4]
end end
echo (expr $num_items - $i)\t$$dir_hist[1][$i] | sed "s|$HOME|~|" echo (expr $num_items - $i)\t$$dir_hist[1][$i] | sed "s|$HOME|~|"
end end
if [ $num_items -eq 1 ] if [ $num_items -eq 1 ]
set last_item '' set last_item ''
else else
set last_item '-'(expr $num_items - 1) set last_item '-'(expr $num_items - 1)
end end
echo -en $budspencer_cursors[2] echo -en $budspencer_cursors[2]
set input_length (expr length (expr $num_items - 1)) set input_length (expr length (expr $num_items - 1))
read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[5])" ♻ Goto [e|0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[5])' -n $input_length -l dir_num read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[5])" ♻ Goto [e|0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[5])' -n $input_length -l dir_num
switch $dir_num switch $dir_num
case (seq 0 (expr $num_items - 1)) case (seq 0 (expr $num_items - 1))
cd $$dir_hist[1][(expr $num_items - $dir_num)] cd $$dir_hist[1][(expr $num_items - $dir_num)]
return 0 return 0
case 'e' case 'e'
read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[5])" ♻ Erase [0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[5])' -n $input_length -l dir_num read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[5])" ♻ Erase [0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[5])' -n $input_length -l dir_num
set -e $dir_hist[1][(expr $num_items - $dir_num)] ^ /dev/null set -e $dir_hist[1][(expr $num_items - $dir_num)] ^ /dev/null
set dir_hist_val (count $$dir_hist) set dir_hist_val (count $$dir_hist)
return 0 return 0
end end
return 1 return 1
end end
#################### ####################
# => Command history # => Command history
#################### ####################
function __budspencer_create_cmd_hist -e fish_prompt -d 'Create command history without duplicates' function __budspencer_create_cmd_hist -e fish_prompt -d 'Create command history without duplicates'
if [ $_ = 'fish' ] if [ $_ = 'fish' ]
set pcount (expr $pcount + 1) set pcount (expr $pcount + 1)
set -l IFS '' set -l IFS ''
set -l cmd (echo $history[1] | fish_indent | expand -t 4) set -l cmd (echo $history[1] | fish_indent | expand -t 4)
# Create prompt history # Create prompt history
set prompt_hist $prompt_hist $cmd set prompt_hist $prompt_hist $cmd
# Create command history # Create command history
if not begin if not begin
expr $cmd : '[cdms] ' > /dev/null expr $cmd : '[cdms] ' > /dev/null
or contains $cmd $budspencer_nocmdhist or contains $cmd $budspencer_nocmdhist
end end
if contains $cmd $$cmd_hist if contains $cmd $$cmd_hist
set -e $cmd_hist[1][(contains -i $cmd $$cmd_hist)] set -e $cmd_hist[1][(contains -i $cmd $$cmd_hist)]
end end
set $cmd_hist $$cmd_hist $cmd set $cmd_hist $$cmd_hist $cmd
end end
end end
set fish_bind_mode insert set fish_bind_mode insert
echo -n \a echo -n \a
end end
function c -d 'List command history, load command from prompt with c <prompt number>' function c -d 'List command history, load command from prompt with c <prompt number>'
set -l num_items (count $$cmd_hist) set -l num_items (count $$cmd_hist)
if [ $num_items -eq 0 ] if [ $num_items -eq 0 ]
set_color $fish_color_error[1] set_color $fish_color_error[1]
echo 'Command history is empty. '(set_color normal)'It will be created automatically.' echo 'Command history is empty. '(set_color normal)'It will be created automatically.'
return return
end end
for i in (seq $num_items) for i in (seq $num_items)
if [ (expr \( $num_items - $i \) \% 2) -eq 0 ] if [ (expr \( $num_items - $i \) \% 2) -eq 0 ]
set_color normal set_color normal
else else
set_color $budspencer_colors[4] set_color $budspencer_colors[4]
end end
echo -n (expr $num_items - $i) echo -n (expr $num_items - $i)
set -l item (echo $$cmd_hist[1][$i]) set -l item (echo $$cmd_hist[1][$i])
echo -n \t$item\n echo -n \t$item\n
end end
if [ $num_items -eq 1 ] if [ $num_items -eq 1 ]
set last_item '' set last_item ''
else else
set last_item '-'(expr $num_items - 1) set last_item '-'(expr $num_items - 1)
end end
echo -en $budspencer_cursors[4] echo -en $budspencer_cursors[4]
set input_length (expr length (expr $num_items - 1)) set input_length (expr length (expr $num_items - 1))
read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[9])" ↩ Exec [e|0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[9])' -n $input_length -l cmd_num read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[9])" ↩ Exec [e|0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[9])' -n $input_length -l cmd_num
switch $cmd_num switch $cmd_num
case (seq 0 (expr $num_items - 1)) case (seq 0 (expr $num_items - 1))
commandline $$cmd_hist[1][(expr $num_items - $cmd_num)] commandline $$cmd_hist[1][(expr $num_items - $cmd_num)]
echo $$cmd_hist[1][(expr $num_items - $cmd_num)] | xsel echo $$cmd_hist[1][(expr $num_items - $cmd_num)] | xsel
return 0 return 0
case 'e' case 'e'
read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[9])" ↩ Erase [0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[9])' -n $input_length -l cmd_num read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[9])" ↩ Erase [0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[9])' -n $input_length -l cmd_num
set -e $cmd_hist[1][(expr $num_items - $cmd_num)] ^ /dev/null set -e $cmd_hist[1][(expr $num_items - $cmd_num)] ^ /dev/null
return 0 return 0
end end
return 1 return 1
end end
############## ##############
# => Bookmarks # => Bookmarks
############## ##############
function mark -d 'Create bookmark for present working directory.' function mark -d 'Create bookmark for present working directory.'
if not contains $PWD $bookmarks if not contains $PWD $bookmarks
set -U bookmarks $PWD $bookmarks set -U bookmarks $PWD $bookmarks
set pwd_hist_lock true set pwd_hist_lock true
commandline -f repaint commandline -f repaint
end end
end end
function unmark -d 'Remove bookmark for present working directory.' function unmark -d 'Remove bookmark for present working directory.'
if contains $PWD $bookmarks if contains $PWD $bookmarks
set -e bookmarks[(contains -i $PWD $bookmarks)] set -e bookmarks[(contains -i $PWD $bookmarks)]
set pwd_hist_lock true set pwd_hist_lock true
commandline -f repaint commandline -f repaint
end end
end end
function m -d 'List bookmarks, jump to directory in list with m <number>' function m -d 'List bookmarks, jump to directory in list with m <number>'
set -l num_items (count $bookmarks) set -l num_items (count $bookmarks)
if [ $num_items -eq 0 ] if [ $num_items -eq 0 ]
set_color $fish_color_error[1] set_color $fish_color_error[1]
echo 'Bookmark list is empty. '(set_color normal)'Enter '(set_color $fish_color_command[1])'mark '(set_color normal)'in INSERT mode or '(set_color $fish_color_command[1])'m '(set_color normal)'in NORMAL mode, if you want to add the current directory to your bookmark list.' echo 'Bookmark list is empty. '(set_color normal)'Enter '(set_color $fish_color_command[1])'mark '(set_color normal)'in INSERT mode or '(set_color $fish_color_command[1])'m '(set_color normal)'in NORMAL mode, if you want to add the current directory to your bookmark list.'
return return
end end
for i in (seq $num_items) for i in (seq $num_items)
if [ $PWD = $bookmarks[$i] ] if [ $PWD = $bookmarks[$i] ]
set_color $budspencer_colors[10] set_color $budspencer_colors[10]
else else
if [ (expr \( $num_items - $i \) \% 2) -eq 0 ] if [ (expr \( $num_items - $i \) \% 2) -eq 0 ]
set_color normal set_color normal
else else
set_color $budspencer_colors[4] set_color $budspencer_colors[4]
end end
end end
echo (expr $num_items - $i)\t$bookmarks[$i] | sed "s|$HOME|~|" echo (expr $num_items - $i)\t$bookmarks[$i] | sed "s|$HOME|~|"
end end
if [ $num_items -eq 1 ] if [ $num_items -eq 1 ]
set last_item '' set last_item ''
else else
set last_item '-'(expr $num_items - 1) set last_item '-'(expr $num_items - 1)
end end
echo -en $budspencer_cursors[1] echo -en $budspencer_cursors[1]
set input_length (expr length (expr $num_items - 1)) set input_length (expr length (expr $num_items - 1))
read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[10])" ⌘ Goto [0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[10])' -n $input_length -l dir_num read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[10])" ⌘ Goto [0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[10])' -n $input_length -l dir_num
switch $dir_num switch $dir_num
case (seq 0 (expr $num_items - 1)) case (seq 0 (expr $num_items - 1))
cd $bookmarks[(expr $num_items - $dir_num)] cd $bookmarks[(expr $num_items - $dir_num)]
return 0 return 0
end end
return 1 return 1
end end
############# #############
# => Sessions # => Sessions
############# #############
function __budspencer_delete_zombi_sessions -d 'Delete zombi sessions' function __budspencer_delete_zombi_sessions -d 'Delete zombi sessions'
for i in $budspencer_sessions_active_pid for i in $budspencer_sessions_active_pid
if not contains $i %fish if not contains $i %fish
set -l item (contains -i $i $budspencer_sessions_active_pid) set -l item (contains -i $i $budspencer_sessions_active_pid)
set -e budspencer_sessions_active_pid[$item] set -e budspencer_sessions_active_pid[$item]
set -e budspencer_sessions_active[$item] set -e budspencer_sessions_active[$item]
end end
end end
end end
function __budspencer_create_new_session -d 'Create a new session' function __budspencer_create_new_session -d 'Create a new session'
set -U budspencer_session_cmd_hist_$argv[1] $$cmd_hist set -U budspencer_session_cmd_hist_$argv[1] $$cmd_hist
set -U budspencer_session_dir_hist_$argv[1] $$dir_hist set -U budspencer_session_dir_hist_$argv[1] $$dir_hist
set -U budspencer_sessions $argv[1] $budspencer_sessions set -U budspencer_sessions $argv[1] $budspencer_sessions
end end
function __budspencer_erase_session -d 'Erase current session' function __budspencer_erase_session -d 'Erase current session'
if [ (count $argv) -eq 1 ] if [ (count $argv) -eq 1 ]
set_color $fish_color_error[1] set_color $fish_color_error[1]
echo 'Missing argument: name of session to erase' echo 'Missing argument: name of session to erase'
return return
end end
if contains $argv[2] $budspencer_sessions_active if contains $argv[2] $budspencer_sessions_active
set_color $fish_color_error[1] set_color $fish_color_error[1]
echo "Session '$argv[2]' cannot be erased because it's currently active." echo "Session '$argv[2]' cannot be erased because it's currently active."
return return
end end
if contains $argv[2] $budspencer_sessions if contains $argv[2] $budspencer_sessions
set -e budspencer_session_cmd_hist_$argv[2] set -e budspencer_session_cmd_hist_$argv[2]
set -e budspencer_session_dir_hist_$argv[2] set -e budspencer_session_dir_hist_$argv[2]
set -e budspencer_sessions[(contains -i $argv[2] $budspencer_sessions)] set -e budspencer_sessions[(contains -i $argv[2] $budspencer_sessions)]
else else
set_color $fish_color_error[1] set_color $fish_color_error[1]
echo "Session '$argv[2]' not found. "(set_color normal)'Enter '(set_color $fish_color_command[1])'s '(set_color normal)'to show a list of all recorded sessions.' echo "Session '$argv[2]' not found. "(set_color normal)'Enter '(set_color $fish_color_command[1])'s '(set_color normal)'to show a list of all recorded sessions.'
end end
end end
function __budspencer_detach_session -d 'Detach current session' function __budspencer_detach_session -d 'Detach current session'
set cmd_hist cmd_hist_nosession set cmd_hist cmd_hist_nosession
set dir_hist dir_hist_nosession set dir_hist dir_hist_nosession
if [ -z $$dir_hist ] ^ /dev/null if [ -z $$dir_hist ] ^ /dev/null
set $dir_hist $PWD set $dir_hist $PWD
end end
set dir_hist_val (count $$dir_hist) set dir_hist_val (count $$dir_hist)
set -e budspencer_sessions_active_pid[$argv] ^ /dev/null set -e budspencer_sessions_active_pid[$argv] ^ /dev/null
set -e budspencer_sessions_active[$argv] ^ /dev/null set -e budspencer_sessions_active[$argv] ^ /dev/null
set budspencer_session_current '' set budspencer_session_current ''
cd $$dir_hist[1][$dir_hist_val] cd $$dir_hist[1][$dir_hist_val]
end end
function __budspencer_attach_session -d 'Attach session' function __budspencer_attach_session -d 'Attach session'
set argv (echo -sn $argv\n | sed 's|[^[:alnum:]]|_|g') set argv (echo -sn $argv\n | sed 's|[^[:alnum:]]|_|g')
if contains $argv[1] $budspencer_sessions_active if contains $argv[1] $budspencer_sessions_active
wmctrl -a "✻ $argv[1]" wmctrl -a "✻ $argv[1]"
else else
wt "✻ $argv[1]" wt "✻ $argv[1]"
__budspencer_detach_session $argv[-1] __budspencer_detach_session $argv[-1]
set budspencer_sessions_active $budspencer_sessions_active $argv[1] set budspencer_sessions_active $budspencer_sessions_active $argv[1]
set budspencer_sessions_active_pid $budspencer_sessions_active_pid %self set budspencer_sessions_active_pid $budspencer_sessions_active_pid %self
set budspencer_session_current $argv[1] set budspencer_session_current $argv[1]
if not contains $argv[1] $budspencer_sessions if not contains $argv[1] $budspencer_sessions
__budspencer_create_new_session $argv[1] __budspencer_create_new_session $argv[1]
end end
set cmd_hist budspencer_session_cmd_hist_$argv[1] set cmd_hist budspencer_session_cmd_hist_$argv[1]
set dir_hist budspencer_session_dir_hist_$argv[1] set dir_hist budspencer_session_dir_hist_$argv[1]
if [ -z $$dir_hist ] ^ /dev/null if [ -z $$dir_hist ] ^ /dev/null
set $dir_hist $PWD set $dir_hist $PWD
end end
set dir_hist_val (count $$dir_hist) set dir_hist_val (count $$dir_hist)
cd $$dir_hist[1][$dir_hist_val] ^ /dev/null cd $$dir_hist[1][$dir_hist_val] ^ /dev/null
end end
end end
function s -d 'Create, delete or attach session' function s -d 'Create, delete or attach session'
__budspencer_delete_zombi_sessions __budspencer_delete_zombi_sessions
if [ (count $argv) -eq 0 ] if [ (count $argv) -eq 0 ]
set -l active_indicator set -l active_indicator
set -l num_items (count $budspencer_sessions) set -l num_items (count $budspencer_sessions)
if [ $num_items -eq 0 ] if [ $num_items -eq 0 ]
set_color $fish_color_error[1] set_color $fish_color_error[1]
echo -n 'Session list is empty. ' echo -n 'Session list is empty. '
set_color normal set_color normal
echo -n 'Enter ' echo -n 'Enter '
set_color $fish_color_command[1] set_color $fish_color_command[1]
echo -n 's ' echo -n 's '
set_color $fish_color_param[1] set_color $fish_color_param[1]
echo -n 'session-name' echo -n 'session-name'
set_color normal set_color normal
echo ' to record the current session.' echo ' to record the current session.'
return return
end end
for i in (seq $num_items) for i in (seq $num_items)
if [ $budspencer_sessions[$i] = $budspencer_session_current ] if [ $budspencer_sessions[$i] = $budspencer_session_current ]
set_color $budspencer_colors[8] set_color $budspencer_colors[8]
else else
if [ (expr \( $num_items - $i \) \% 2) -eq 0 ] if [ (expr \( $num_items - $i \) \% 2) -eq 0 ]
set_color normal set_color normal
else else
set_color $budspencer_colors[4] set_color $budspencer_colors[4]
end end
end end
if contains $budspencer_sessions[$i] $budspencer_sessions_active if contains $budspencer_sessions[$i] $budspencer_sessions_active
set active_indicator '✻ ' set active_indicator '✻ '
else else
set active_indicator ' ' set active_indicator ' '
end end
echo (expr $num_items - $i)\t$active_indicator$budspencer_sessions[$i] echo (expr $num_items - $i)\t$active_indicator$budspencer_sessions[$i]
end end
if [ $num_items -eq 1 ] if [ $num_items -eq 1 ]
set last_item '' set last_item ''
else else
set last_item '-'(expr $num_items - 1) set last_item '-'(expr $num_items - 1)
end end
echo -en $budspencer_cursors[3] echo -en $budspencer_cursors[3]
set input_length (expr length (expr $num_items - 1)) set input_length (expr length (expr $num_items - 1))
read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[8])" ✻ Attach [e|0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[8])' -n $input_length -l session_num read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[8])" ✻ Attach [e|0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[8])' -n $input_length -l session_num
switch $session_num switch $session_num
case (seq 0 (expr $num_items - 1)) case (seq 0 (expr $num_items - 1))
set argv[1] $budspencer_sessions[(expr $num_items - $session_num)] set argv[1] $budspencer_sessions[(expr $num_items - $session_num)]
case 'e' case 'e'
read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[8])" ✻ Erase [0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[8])' -n $input_length -l session_num read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[8])" ✻ Erase [0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[8])' -n $input_length -l session_num
__budspencer_erase_session -e $budspencer_sessions[(expr $num_items - $session_num)] __budspencer_erase_session -e $budspencer_sessions[(expr $num_items - $session_num)]
return 0 return 0
case '*' case '*'
return 1 return 1
end end
end end
set -l item (contains -i %self $budspencer_sessions_active_pid ^ /dev/null) set -l item (contains -i %self $budspencer_sessions_active_pid ^ /dev/null)
switch $argv[1] switch $argv[1]
case '-e' case '-e'
__budspencer_erase_session $argv __budspencer_erase_session $argv
case '-d' case '-d'
wt 'fish' wt 'fish'
__budspencer_detach_session $item __budspencer_detach_session $item
case '-*' case '-*'
set_color $fish_color_error[1] set_color $fish_color_error[1]
echo "Invalid argument: $argv[1]" echo "Invalid argument: $argv[1]"
case '*' case '*'
__budspencer_attach_session $argv $item __budspencer_attach_session $argv $item
end end
end end
##################################### #####################################
# => Commandline editing with $EDITOR # => Commandline editing with $EDITOR
##################################### #####################################
function __budspencer_edit_comandline -d 'Open current commandline with your editor' function __budspencer_edit_commandline -d 'Open current commandline with your editor'
commandline > $budspencer_tmpfile commandline | fish_indent > $budspencer_tmpfile
eval $EDITOR $budspencer_tmpfile eval $EDITOR $budspencer_tmpfile
if [ -s $budspencer_tmpfile ] if [ -s $budspencer_tmpfile ]
commandline (sed 's|^\s*||' $budspencer_tmpfile) commandline (sed 's|^\s*||' $budspencer_tmpfile)
else else
commandline '' commandline ''
end end
rm $budspencer_tmpfile rm $budspencer_tmpfile
end end
################ ################
# => Git segment # => Git segment
################ ################
function __budspencer_prompt_git_branch -d 'Return the current branch name' function __budspencer_prompt_git_branch -d 'Return the current branch name'
set -l branch (command git symbolic-ref HEAD ^ /dev/null | sed -e 's|^refs/heads/||') set -l branch (command git symbolic-ref HEAD ^ /dev/null | sed -e 's|^refs/heads/||')
if not test $branch > /dev/null if not test $branch > /dev/null
set -l position (command git describe --contains --all HEAD ^ /dev/null) set -l position (command git describe --contains --all HEAD ^ /dev/null)
if not test $position > /dev/null if not test $position > /dev/null
set -l commit (command git rev-parse HEAD ^ /dev/null | sed 's|\(^.......\).*|\1|') set -l commit (command git rev-parse HEAD ^ /dev/null | sed 's|\(^.......\).*|\1|')
echo -n (set_color -b $budspencer_colors[11])''(set_color $budspencer_colors[1])' ➦ '$commit' '(set_color $budspencer_colors[11]) echo -n (set_color -b $budspencer_colors[11])''(set_color $budspencer_colors[1])' ➦ '$commit' '(set_color $budspencer_colors[11])
else else
echo -n (set_color -b $budspencer_colors[9])''(set_color $budspencer_colors[1])'  '$position' '(set_color $budspencer_colors[9]) echo -n (set_color -b $budspencer_colors[9])''(set_color $budspencer_colors[1])'  '$position' '(set_color $budspencer_colors[9])
end end
else else
echo -n (set_color -b $budspencer_colors[3])''(set_color $budspencer_colors[1])'  '$branch' '(set_color $budspencer_colors[3]) echo -n (set_color -b $budspencer_colors[3])''(set_color $budspencer_colors[1])'  '$branch' '(set_color $budspencer_colors[3])
end end
end end
###################### ######################
# => Bind-mode segment # => Bind-mode segment
###################### ######################
function __budspencer_prompt_bindmode -d 'Displays the current mode' function __budspencer_prompt_bindmode -d 'Displays the current mode'
switch $fish_bind_mode switch $fish_bind_mode
case default case default
set budspencer_current_bindmode_color $budspencer_colors[10] set budspencer_current_bindmode_color $budspencer_colors[10]
echo -en $budspencer_cursors[1] echo -en $budspencer_cursors[1]
case insert case insert
set budspencer_current_bindmode_color $budspencer_colors[5] set budspencer_current_bindmode_color $budspencer_colors[5]
echo -en $budspencer_cursors[2] echo -en $budspencer_cursors[2]
if [ $pwd_hist_lock = true ] if [ "$pwd_hist_lock" = true ]
set pwd_hist_lock false set pwd_hist_lock false
__budspencer_create_dir_hist __budspencer_create_dir_hist
end end
case visual case visual
set budspencer_current_bindmode_color $budspencer_colors[8] set budspencer_current_bindmode_color $budspencer_colors[8]
echo -en $budspencer_cursors[3] echo -en $budspencer_cursors[3]
end end
if [ (count $budspencer_prompt_error) -eq 1 ] if [ (count $budspencer_prompt_error) -eq 1 ]
set budspencer_current_bindmode_color $budspencer_colors[7] set budspencer_current_bindmode_color $budspencer_colors[7]
end end
set_color -b $budspencer_current_bindmode_color $budspencer_colors[1] set_color -b $budspencer_current_bindmode_color $budspencer_colors[1]
echo -n " $pcount " echo -n " $pcount "
set_color -b $budspencer_colors[1] $budspencer_current_bindmode_color set_color -b $budspencer_colors[1] $budspencer_current_bindmode_color
end end
#################### ####################
# => Symbols segment # => Symbols segment
#################### ####################
function __budspencer_prompt_left_symbols -d 'Display symbols' function __budspencer_prompt_left_symbols -d 'Display symbols'
set -l jobs (jobs | wc -l) set -l jobs (jobs | wc -l)
if [ -e ~/.taskrc ] if [ -e ~/.taskrc ]
set todo (task due.before:tomorrow ^ /dev/null | tail -1 | cut -f1 -d' ') set todo (task due.before:tomorrow ^ /dev/null | tail -1 | cut -f1 -d' ')
end end
if [ -e ~/.reminders ] if [ -e ~/.reminders ]
set appointments (rem -a | cut -f1 -d' ') set appointments (rem -a | cut -f1 -d' ')
end end
if [ (count $todo) -eq 0 ] if [ (count $todo) -eq 0 ]
set todo 0 set todo 0
end end
if [ (count $appointments) -eq 0 ] if [ (count $appointments) -eq 0 ]
set appointments 0 set appointments 0
end end
set_color -b $budspencer_colors[2] set_color -b $budspencer_colors[2]
echo -n '' echo -n ''
if [ $symbols_style = 'symbols' ] if [ $symbols_style = 'symbols' ]
if [ $budspencer_session_current != '' ] if [ $budspencer_session_current != '' ]
set_color -o $budspencer_colors[8] set_color -o $budspencer_colors[8]
echo -n ' ✻' echo -n ' ✻'
end end
if contains $PWD $bookmarks if contains $PWD $bookmarks
set_color -o $budspencer_colors[10] set_color -o $budspencer_colors[10]
echo -n ' ⌘' echo -n ' ⌘'
end end
if set -q -x VIM if set -q -x VIM
set_color -o $budspencer_colors[9] set_color -o $budspencer_colors[9]
echo -n ' V' echo -n ' V'
end end
if set -q -x RANGER_LEVEL if set -q -x RANGER_LEVEL
set_color -o $budspencer_colors[9] set_color -o $budspencer_colors[9]
echo -n ' R' echo -n ' R'
end end
if [ $jobs -gt 0 ] if [ $jobs -gt 0 ]
set_color -o $budspencer_colors[11] set_color -o $budspencer_colors[11]
echo -n ' ⚙' echo -n ' ⚙'
end end
if [ ! -w . ] if [ ! -w . ]
set_color -o $budspencer_colors[6] set_color -o $budspencer_colors[6]
echo -n ' ' echo -n ' '
end end
if [ $todo -gt 0 ] if [ $todo -gt 0 ]
set_color -o $budspencer_colors[4] set_color -o $budspencer_colors[4]
echo -n ' ⚔' echo -n ' ⚔'
end end
if [ $appointments -gt 0 ] if [ $appointments -gt 0 ]
set_color -o $budspencer_colors[5] set_color -o $budspencer_colors[5]
echo -n ' ⚑' echo -n ' ⚑'
end end
if [ $last_status -eq 0 ] if [ $last_status -eq 0 ]
set_color -o $budspencer_colors[12] set_color -o $budspencer_colors[12]
echo -n ' ✔' echo -n ' ✔'
else else
set_color -o $budspencer_colors[7] set_color -o $budspencer_colors[7]
echo -n ' ✘' echo -n ' ✘'
end end
if [ $USER = 'root' ] if [ $USER = 'root' ]
set_color -o $budspencer_colors[6] set_color -o $budspencer_colors[6]
echo -n ' ⚡' echo -n ' ⚡'
end end
else else
if [ $budspencer_session_current != '' ] ^ /dev/null if [ $budspencer_session_current != '' ] ^ /dev/null
set_color $budspencer_colors[8] set_color $budspencer_colors[8]
echo -n ' '(expr (count $budspencer_sessions) - (contains -i $budspencer_session_current $budspencer_sessions)) echo -n ' '(expr (count $budspencer_sessions) - (contains -i $budspencer_session_current $budspencer_sessions))
end end
if contains $PWD $bookmarks if contains $PWD $bookmarks
set_color $budspencer_colors[10] set_color $budspencer_colors[10]
echo -n ' '(expr (count $bookmarks) - (contains -i $PWD $bookmarks)) echo -n ' '(expr (count $bookmarks) - (contains -i $PWD $bookmarks))
end end
if set -q -x VIM if set -q -x VIM
set_color -o $budspencer_colors[9] set_color -o $budspencer_colors[9]
echo -n ' V' echo -n ' V'
set_color normal set_color normal
end end
if set -q -x RANGER_LEVEL if set -q -x RANGER_LEVEL
set_color -b $budspencer_colors[2] $budspencer_colors[9] set_color -b $budspencer_colors[2] $budspencer_colors[9]
echo -n ' '$RANGER_LEVEL echo -n ' '$RANGER_LEVEL
end end
if [ $jobs -gt 0 ] if [ $jobs -gt 0 ]
set_color -b $budspencer_colors[2] $budspencer_colors[11] set_color -b $budspencer_colors[2] $budspencer_colors[11]
echo -n ' '$jobs echo -n ' '$jobs
end end
if [ ! -w . ] if [ ! -w . ]
set_color -o $budspencer_colors[6] set_color -o $budspencer_colors[6]
echo -n ' ' echo -n ' '
set_color normal set_color normal
end end
if [ $todo -gt 0 ] if [ $todo -gt 0 ]
set_color -b $budspencer_colors[2] $budspencer_colors[4] set_color -b $budspencer_colors[2] $budspencer_colors[4]
echo -n " $todo" echo -n " $todo"
end end
if [ $appointments -gt 0 ] if [ $appointments -gt 0 ]
set_color -b $budspencer_colors[2] $budspencer_colors[5] set_color -b $budspencer_colors[2] $budspencer_colors[5]
echo -n " $appointments" echo -n " $appointments"
end end
if [ $last_status -eq 0 ] if [ $last_status -eq 0 ]
set_color -b $budspencer_colors[2] $budspencer_colors[12] set_color -b $budspencer_colors[2] $budspencer_colors[12]
echo -n ' '$last_status echo -n ' '$last_status
else else
set_color -b $budspencer_colors[2] $budspencer_colors[7] set_color -b $budspencer_colors[2] $budspencer_colors[7]
echo -n ' '$last_status echo -n ' '$last_status
end end
if [ $USER = 'root' ] if [ $USER = 'root' ]
set_color -o $budspencer_colors[6] set_color -o $budspencer_colors[6]
echo -n ' ⚡' echo -n ' ⚡'
end end
end end
echo -n ' ' echo -n ' '
set_color -b normal $budspencer_colors[2] set_color -b normal $budspencer_colors[2]
end end
############################################################################### ###############################################################################
...@@ -639,37 +649,37 @@ set -g symbols_style 'symbols' ...@@ -639,37 +649,37 @@ set -g symbols_style 'symbols'
# Load user defined key bindings # Load user defined key bindings
if functions --query fish_user_key_bindings if functions --query fish_user_key_bindings
fish_user_key_bindings fish_user_key_bindings
end end
# Set favorite editor # Set favorite editor
if not set -q EDITOR if not set -q EDITOR
set -g EDITOR vi set -g EDITOR vi
end end
# Source config file # Source config file
if [ -e $budspencer_config ] if [ -e $budspencer_config ]
source $budspencer_config source $budspencer_config
end end
# Don't save in command history # Don't save in command history
if not set -q budspencer_nocmdhist if not set -q budspencer_nocmdhist
set -U budspencer_nocmdhist 'c' 'd' 'll' 'ls' 'm' 's' set -U budspencer_nocmdhist 'c' 'd' 'll' 'ls' 'm' 's'
end end
# Set PWD segment style # Set PWD segment style
if not set -q budspencer_pwdstyle if not set -q budspencer_pwdstyle
set -U budspencer_pwdstyle short long none set -U budspencer_pwdstyle short long none
end end
set pwd_style $budspencer_pwdstyle[1] set pwd_style $budspencer_pwdstyle[1]
# Cd to newest bookmark if this is a login shell # Cd to newest bookmark if this is a login shell
if not begin if not begin
set -q -x LOGIN set -q -x LOGIN
or set -q -x RANGER_LEVEL or set -q -x RANGER_LEVEL
or set -q -x VIM or set -q -x VIM
end ^ /dev/null end ^ /dev/null
cd $bookmarks[1] cd $bookmarks[1]
end end
set -x LOGIN $USER set -x LOGIN $USER
...@@ -678,6 +688,6 @@ set -x LOGIN $USER ...@@ -678,6 +688,6 @@ set -x LOGIN $USER
############################################################################### ###############################################################################
function fish_prompt -d 'Write out the left prompt of the budspencer theme' function fish_prompt -d 'Write out the left prompt of the budspencer theme'
set -g last_status $status set -g last_status $status
echo -n -s (__budspencer_prompt_bindmode) (__budspencer_prompt_git_branch) (__budspencer_prompt_left_symbols) '' ' ' echo -n -s (__budspencer_prompt_bindmode) (__budspencer_prompt_git_branch) (__budspencer_prompt_left_symbols) '' ' '
end end
...@@ -27,205 +27,206 @@ ...@@ -27,205 +27,206 @@
# => Toggle functions # => Toggle functions
##################### #####################
function __budspencer_toggle_symbols -d 'Toggles style of symbols, press # in NORMAL or VISUAL mode' function __budspencer_toggle_symbols -d 'Toggles style of symbols, press # in NORMAL or VISUAL mode'
if [ $symbols_style = 'symbols' ] if [ $symbols_style = 'symbols' ]
set symbols_style 'numbers' set symbols_style 'numbers'
else else
set symbols_style 'symbols' set symbols_style 'symbols'
end end
set pwd_hist_lock true set pwd_hist_lock true
commandline -f repaint commandline -f repaint
end end
function __budspencer_toggle_pwd -d 'Toggles style of pwd segment, press space bar in NORMAL or VISUAL mode' function __budspencer_toggle_pwd -d 'Toggles style of pwd segment, press space bar in NORMAL or VISUAL mode'
for i in (seq (count $budspencer_pwdstyle)) for i in (seq (count $budspencer_pwdstyle))
if [ $budspencer_pwdstyle[$i] = $pwd_style ] if [ $budspencer_pwdstyle[$i] = $pwd_style ]
set pwd_style $budspencer_pwdstyle[(expr $i \% (count $budspencer_pwdstyle) + 1)] set pwd_style $budspencer_pwdstyle[(expr $i \% (count $budspencer_pwdstyle) + 1)]
set pwd_hist_lock true set pwd_hist_lock true
commandline -f repaint commandline -f repaint
break break
end end
end end
end end
############################# #############################
# => Command duration segment # => Command duration segment
############################# #############################
function __budspencer_cmd_duration -d 'Displays the elapsed time of last command' function __budspencer_cmd_duration -d 'Displays the elapsed time of last command'
set -l seconds '' set -l seconds ''
set -l minutes '' set -l minutes ''
set -l hours '' set -l hours ''
set -l days '' set -l days ''
set -l cmd_duration (expr $CMD_DURATION / 1000) set -l cmd_duration (expr $CMD_DURATION / 1000)
if [ $cmd_duration -gt 0 ] if [ $cmd_duration -gt 0 ]
set seconds (expr $cmd_duration \% 68400 \% 3600 \% 60)'s' set seconds (expr $cmd_duration \% 68400 \% 3600 \% 60)'s'
if [ $cmd_duration -ge 60 ] if [ $cmd_duration -ge 60 ]
set minutes (expr $cmd_duration \% 68400 \% 3600 / 60)'m' set minutes (expr $cmd_duration \% 68400 \% 3600 / 60)'m'
if [ $cmd_duration -ge 3600 ] if [ $cmd_duration -ge 3600 ]
set hours (expr $cmd_duration \% 68400 / 3600)'h' set hours (expr $cmd_duration \% 68400 / 3600)'h'
if [ $cmd_duration -ge 68400 ] if [ $cmd_duration -ge 68400 ]
set days (expr $cmd_duration / 68400)'d' set days (expr $cmd_duration / 68400)'d'
end end
end end
end end
if [ $last_status -ne 0 ] if [ $last_status -ne 0 ]
echo -n (set_color $budspencer_colors[2])''(set_color -b $budspencer_colors[2] $budspencer_colors[7])' '$days$hours$minutes$seconds echo -n (set_color $budspencer_colors[2])''(set_color -b $budspencer_colors[2] $budspencer_colors[7])' '$days$hours$minutes$seconds
else else
echo -n (set_color $budspencer_colors[2])''(set_color -b $budspencer_colors[2] $budspencer_colors[12])' '$days$hours$minutes$seconds echo -n (set_color $budspencer_colors[2])''(set_color -b $budspencer_colors[2] $budspencer_colors[12])' '$days$hours$minutes$seconds
end end
end end
end end
################ ################
# => Git segment # => Git segment
################ ################
function __budspencer_is_git_ahead_or_behind -d 'Check if there are unpulled or unpushed commits' function __budspencer_is_git_ahead_or_behind -d 'Check if there are unpulled or unpushed commits'
command git rev-list --count --left-right 'HEAD...@{upstream}' ^ /dev/null | sed 's|\s\+|\n|g' command git rev-list --count --left-right 'HEAD...@{upstream}' ^ /dev/null | sed 's|\s\+|\n|g'
end end
function __budspencer_git_status -d 'Check git status' function __budspencer_git_status -d 'Check git status'
set -l git_status (command git status --porcelain ^/dev/null | cut -c 1-2) set -l git_status (command git status --porcelain ^/dev/null | cut -c 1-2)
set -l added (echo -sn $git_status\n | egrep -c "[ACDMT][ MT]|[ACMT]D") set -l added (echo -sn $git_status\n | egrep -c "[ACDMT][ MT]|[ACMT]D")
set -l deleted (echo -sn $git_status\n | egrep -c "[ ACMRT]D") set -l deleted (echo -sn $git_status\n | egrep -c "[ ACMRT]D")
set -l modified (echo -sn $git_status\n | egrep -c ".[MT]") set -l modified (echo -sn $git_status\n | egrep -c ".[MT]")
set -l renamed (echo -sn $git_status\n | egrep -c "R.") set -l renamed (echo -sn $git_status\n | egrep -c "R.")
set -l unmerged (echo -sn $git_status\n | egrep -c "AA|DD|U.|.U") set -l unmerged (echo -sn $git_status\n | egrep -c "AA|DD|U.|.U")
set -l untracked (echo -sn $git_status\n | egrep -c "\?\?") set -l untracked (echo -sn $git_status\n | egrep -c "\?\?")
echo -n $added\n$deleted\n$modified\n$renamed\n$unmerged\n$untracked echo -n $added\n$deleted\n$modified\n$renamed\n$unmerged\n$untracked
end end
function __budspencer_is_git_stashed -d 'Check if there are stashed commits' function __budspencer_is_git_stashed -d 'Check if there are stashed commits'
command git stash list ^ /dev/null | wc -l command git log --format="%gd" -g $argv 'refs/stash' -- ^ /dev/null | wc -l
end end
function __budspencer_prompt_git_symbols -d 'Displays the git symbols' function __budspencer_prompt_git_symbols -d 'Displays the git symbols'
set -l is_repo (command git rev-parse --is-inside-work-tree ^/dev/null) set -l is_repo (command git rev-parse --is-inside-work-tree ^/dev/null)
set -l git_ahead_behind (__budspencer_is_git_ahead_or_behind) if [ -z $is_repo ]
set -l git_status (__budspencer_git_status) return
set -l git_stashed (__budspencer_is_git_stashed) end
set -l git_ahead_behind (__budspencer_is_git_ahead_or_behind)
set -l git_status (__budspencer_git_status)
set -l git_stashed (__budspencer_is_git_stashed)
if begin if [ (expr $git_status[1] + $git_status[2] + $git_status[3] + $git_status[4] + $git_status[5] + $git_status[6] + $git_stashed) -ne 0 ]
[ $is_repo=true ] set_color $budspencer_colors[3]
[ (expr $git_status[1] + $git_status[2] + $git_status[3] + $git_status[4] + $git_status[5] + $git_status[6]) -ne 0 ] echo -n ''
end set_color -b $budspencer_colors[3]
set_color $budspencer_colors[3] if [ $symbols_style = 'symbols' ]
echo -n '' if [ (count $git_ahead_behind) -eq 2 ]
set_color -b $budspencer_colors[3] if [ $git_ahead_behind[1] -gt 0 ]
if [ $symbols_style = 'symbols' ] set_color -o $budspencer_colors[5]
if [ (count $git_ahead_behind) -eq 2 ] echo -n ' ↑'
if [ $git_ahead_behind[1] -gt 0 ] end
set_color -o $budspencer_colors[5] if [ $git_ahead_behind[2] -gt 0 ]
echo -n ' ↑' set_color -o $budspencer_colors[5]
end echo -n ' ↓'
if [ $git_ahead_behind[2] -gt 0 ] end
set_color -o $budspencer_colors[5] end
echo -n ' ↓' if [ $git_status[1] -gt 0 ]
end set_color -o $budspencer_colors[12]
end echo -n ' +'
if [ $git_status[1] -gt 0 ] end
set_color -o $budspencer_colors[12] if [ $git_status[2] -gt 0 ]
echo -n ' +' set_color -o $budspencer_colors[7]
end echo -n ' –'
if [ $git_status[2] -gt 0 ] end
set_color -o $budspencer_colors[7] if [ $git_status[3] -gt 0 ]
echo -n ' –' set_color -o $budspencer_colors[10]
end echo -n ' ✱'
if [ $git_status[3] -gt 0 ] end
set_color -o $budspencer_colors[10] if [ $git_status[4] -gt 0 ]
echo -n ' ✱' set_color -o $budspencer_colors[8]
end echo -n ' →'
if [ $git_status[4] -gt 0 ] end
set_color -o $budspencer_colors[8] if [ $git_status[5] -gt 0 ]
echo -n ' →' set_color -o $budspencer_colors[9]
end echo -n ' ═'
if [ $git_status[5] -gt 0 ] end
set_color -o $budspencer_colors[9] if [ $git_status[6] -gt 0 ]
echo -n ' ═' set_color -o $budspencer_colors[4]
end echo -n ' ●'
if [ $git_status[6] -gt 0 ] end
set_color -o $budspencer_colors[4] if [ $git_stashed -gt 0 ]
echo -n ' ●' set_color -o $budspencer_colors[11]
end echo -n ' ✭'
if [ $git_stashed -gt 0 ] end
set_color -o $budspencer_colors[11] else
echo -n ' ✭' if [ (count $git_ahead_behind) -eq 2 ]
end if [ $git_ahead_behind[1] -gt 0 ]
else set_color $budspencer_colors[5]
if [ (count $git_ahead_behind) -eq 2 ] echo -n ' '$git_ahead_behind[1]
if [ $git_ahead_behind[1] -gt 0 ] end
set_color $budspencer_colors[5] if [ $git_ahead_behind[2] -gt 0 ]
echo -n ' '$git_ahead_behind[1] set_color $budspencer_colors[5]
end echo -n ' '$git_ahead_behind[2]
if [ $git_ahead_behind[2] -gt 0 ] end
set_color $budspencer_colors[5] end
echo -n ' '$git_ahead_behind[2] if [ $git_status[1] -gt 0 ]
end set_color $budspencer_colors[12]
end echo -n ' '$git_status[1]
if [ $git_status[1] -gt 0 ] end
set_color $budspencer_colors[12] if [ $git_status[2] -gt 0 ]
echo -n ' '$git_status[1] set_color $budspencer_colors[7]
end echo -n ' '$git_status[2]
if [ $git_status[2] -gt 0 ] end
set_color $budspencer_colors[7] if [ $git_status[3] -gt 0 ]
echo -n ' '$git_status[2] set_color $budspencer_colors[10]
end echo -n ' '$git_status[3]
if [ $git_status[3] -gt 0 ] end
set_color $budspencer_colors[10] if [ $git_status[4] -gt 0 ]
echo -n ' '$git_status[3] set_color $budspencer_colors[8]
end echo -n ' '$git_status[4]
if [ $git_status[4] -gt 0 ] end
set_color $budspencer_colors[8] if [ $git_status[5] -gt 0 ]
echo -n ' '$git_status[4] set_color $budspencer_colors[9]
end echo -n ' '$git_status[5]
if [ $git_status[5] -gt 0 ] end
set_color $budspencer_colors[9] if [ $git_status[6] -gt 0 ]
echo -n ' '$git_status[5] set_color $budspencer_colors[4]
end echo -n ' '$git_status[6]
if [ $git_status[6] -gt 0 ] end
set_color $budspencer_colors[4] if [ $git_stashed -gt 0 ]
echo -n ' '$git_status[6] set_color $budspencer_colors[11]
end echo -n ' '$git_stashed
if [ $git_stashed -gt 0 ] end
set_color $budspencer_colors[11] end
echo -n ' '$git_stashed set_color -b $budspencer_colors[3] normal
end end
end
set_color -b $budspencer_colors[3] normal
end
end end
################ ################
# => PWD segment # => PWD segment
################ ################
function __budspencer_prompt_pwd -d 'Displays the present working directory' function __budspencer_prompt_pwd -d 'Displays the present working directory'
set -l user_host ' ' set -l user_host ' '
if set -q SSH_CLIENT if set -q SSH_CLIENT
if [ $symbols_style = 'symbols' ] if [ $symbols_style = 'symbols' ]
switch $pwd_style switch $pwd_style
case short case short
set user_host " $USER@"(hostname -s)':' set user_host " $USER@"(hostname -s)':'
case long case long
set user_host " $USER@"(hostname -f)':' set user_host " $USER@"(hostname -f)':'
end end
else else
set user_host " $USER@"(hostname -i)':' set user_host " $USER@"(hostname -i)':'
end end
end end
set_color $budspencer_current_bindmode_color set_color $budspencer_current_bindmode_color
echo -n '' echo -n ''
set_color normal set_color normal
set_color -b $budspencer_current_bindmode_color $budspencer_colors[1] set_color -b $budspencer_current_bindmode_color $budspencer_colors[1]
if [ (count $budspencer_prompt_error) != 1 ] if [ (count $budspencer_prompt_error) != 1 ]
switch $pwd_style switch $pwd_style
case short case short
echo -n $user_host(prompt_pwd)' ' echo -n $user_host(prompt_pwd)' '
case long case long
echo -n $user_host$PWD' ' echo -n $user_host(pwd)' '
end end
else else
echo -n " $budspencer_prompt_error " echo -n " $budspencer_prompt_error "
set -e budspencer_prompt_error[1] set -e budspencer_prompt_error[1]
end end
set_color normal set_color normal
end end
############################################################################### ###############################################################################
...@@ -233,6 +234,6 @@ end ...@@ -233,6 +234,6 @@ end
############################################################################### ###############################################################################
function fish_right_prompt -d 'Write out the right prompt of the budspencer theme' function fish_right_prompt -d 'Write out the right prompt of the budspencer theme'
echo -n (__budspencer_cmd_duration) (__budspencer_prompt_git_symbols) (__budspencer_prompt_pwd) echo -n (__budspencer_cmd_duration) (__budspencer_prompt_git_symbols) (__budspencer_prompt_pwd)
set_color normal set_color normal
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment