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,
vi is used.
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
......
......@@ -40,7 +40,9 @@ if [ $fish_key_bindings = 'fish_vi_key_bindings' ]
bind H __budspencer_cd_prev
bind m mark
bind M unmark
bind . __budspencer_edit_comandline
bind . __budspencer_edit_commandline
bind \cv __budspencer_edit_commandline
bind -M insert \cv __budspencer_edit_commandline
bind -M insert \n __budspencer_preexec
bind \n __budspencer_preexec
end
......@@ -110,21 +112,29 @@ function __budspencer_preexec -d 'Execute after hitting <Enter> before doing any
return
end
end
end
commandline -f execute
end
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
######################
# => Directory history
######################
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
set -e $dir_hist[1][(contains -i $PWD $$dir_hist)]
end
set $dir_hist $$dir_hist $PWD
set -g dir_hist_val (count $$dir_hist)
end
end
end
function __budspencer_cd_prev -d 'Change to previous directory, press H in NORMAL mode.'
......@@ -133,7 +143,7 @@ function __budspencer_cd_prev -d 'Change to previous directory, press H in NORMA
set pwd_hist_lock true
cd $$dir_hist[1][$dir_hist_val]
commandline -f repaint
end
end
end
function __budspencer_cd_next -d 'Change to next directory, press L in NORMAL mode.'
......@@ -142,7 +152,7 @@ function __budspencer_cd_next -d 'Change to next directory, press L in NORMAL mo
set pwd_hist_lock true
cd $$dir_hist[1][$dir_hist_val]
commandline -f repaint
end
end
end
function d -d 'List directory history, jump to directory in list with d <number>'
......@@ -151,34 +161,34 @@ function d -d 'List directory history, jump to directory in list with d <number>
set_color $fish_color_error[1]
echo 'Directory history is empty. '(set_color normal)'It will be created automatically'
return
end
for i in (seq $num_items)
end
for i in (seq $num_items)
if [ (expr \( $num_items - $i \) \% 2) -eq 0 ]
set_color normal
else
set_color $budspencer_colors[4]
end
echo (expr $num_items - $i)\t$$dir_hist[1][$i] | sed "s|$HOME|~|"
end
if [ $num_items -eq 1 ]
end
if [ $num_items -eq 1 ]
set last_item ''
else
else
set last_item '-'(expr $num_items - 1)
end
echo -en $budspencer_cursors[2]
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
switch $dir_num
case (seq 0 (expr $num_items - 1))
end
echo -en $budspencer_cursors[2]
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
switch $dir_num
case (seq 0 (expr $num_items - 1))
cd $$dir_hist[1][(expr $num_items - $dir_num)]
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
set -e $dir_hist[1][(expr $num_items - $dir_num)] ^ /dev/null
set dir_hist_val (count $$dir_hist)
return 0
end
return 1
end
return 1
end
####################
......@@ -201,9 +211,9 @@ function __budspencer_create_cmd_hist -e fish_prompt -d 'Create command history
end
set $cmd_hist $$cmd_hist $cmd
end
end
set fish_bind_mode insert
echo -n \a
end
set fish_bind_mode insert
echo -n \a
end
function c -d 'List command history, load command from prompt with c <prompt number>'
......@@ -212,8 +222,8 @@ function c -d 'List command history, load command from prompt with c <prompt num
set_color $fish_color_error[1]
echo 'Command history is empty. '(set_color normal)'It will be created automatically.'
return
end
for i in (seq $num_items)
end
for i in (seq $num_items)
if [ (expr \( $num_items - $i \) \% 2) -eq 0 ]
set_color normal
else
......@@ -222,26 +232,26 @@ function c -d 'List command history, load command from prompt with c <prompt num
echo -n (expr $num_items - $i)
set -l item (echo $$cmd_hist[1][$i])
echo -n \t$item\n
end
if [ $num_items -eq 1 ]
end
if [ $num_items -eq 1 ]
set last_item ''
else
else
set last_item '-'(expr $num_items - 1)
end
echo -en $budspencer_cursors[4]
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
switch $cmd_num
case (seq 0 (expr $num_items - 1))
end
echo -en $budspencer_cursors[4]
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
switch $cmd_num
case (seq 0 (expr $num_items - 1))
commandline $$cmd_hist[1][(expr $num_items - $cmd_num)]
echo $$cmd_hist[1][(expr $num_items - $cmd_num)] | xsel
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
set -e $cmd_hist[1][(expr $num_items - $cmd_num)] ^ /dev/null
return 0
end
return 1
end
return 1
end
##############
......@@ -252,7 +262,7 @@ function mark -d 'Create bookmark for present working directory.'
set -U bookmarks $PWD $bookmarks
set pwd_hist_lock true
commandline -f repaint
end
end
end
function unmark -d 'Remove bookmark for present working directory.'
......@@ -260,7 +270,7 @@ function unmark -d 'Remove bookmark for present working directory.'
set -e bookmarks[(contains -i $PWD $bookmarks)]
set pwd_hist_lock true
commandline -f repaint
end
end
end
function m -d 'List bookmarks, jump to directory in list with m <number>'
......@@ -269,8 +279,8 @@ function m -d 'List bookmarks, jump to directory in list with m <number>'
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.'
return
end
for i in (seq $num_items)
end
for i in (seq $num_items)
if [ $PWD = $bookmarks[$i] ]
set_color $budspencer_colors[10]
else
......@@ -281,21 +291,21 @@ function m -d 'List bookmarks, jump to directory in list with m <number>'
end
end
echo (expr $num_items - $i)\t$bookmarks[$i] | sed "s|$HOME|~|"
end
if [ $num_items -eq 1 ]
end
if [ $num_items -eq 1 ]
set last_item ''
else
else
set last_item '-'(expr $num_items - 1)
end
echo -en $budspencer_cursors[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
switch $dir_num
case (seq 0 (expr $num_items - 1))
end
echo -en $budspencer_cursors[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
switch $dir_num
case (seq 0 (expr $num_items - 1))
cd $bookmarks[(expr $num_items - $dir_num)]
return 0
end
return 1
end
return 1
end
#############
......@@ -308,7 +318,7 @@ function __budspencer_delete_zombi_sessions -d 'Delete zombi sessions'
set -e budspencer_sessions_active_pid[$item]
set -e budspencer_sessions_active[$item]
end
end
end
end
function __budspencer_create_new_session -d 'Create a new session'
......@@ -322,20 +332,20 @@ function __budspencer_erase_session -d 'Erase current session'
set_color $fish_color_error[1]
echo 'Missing argument: name of session to erase'
return
end
if contains $argv[2] $budspencer_sessions_active
end
if contains $argv[2] $budspencer_sessions_active
set_color $fish_color_error[1]
echo "Session '$argv[2]' cannot be erased because it's currently active."
return
end
if contains $argv[2] $budspencer_sessions
end
if contains $argv[2] $budspencer_sessions
set -e budspencer_session_cmd_hist_$argv[2]
set -e budspencer_session_dir_hist_$argv[2]
set -e budspencer_sessions[(contains -i $argv[2] $budspencer_sessions)]
else
else
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.'
end
end
end
function __budspencer_detach_session -d 'Detach current session'
......@@ -343,19 +353,19 @@ function __budspencer_detach_session -d 'Detach current session'
set dir_hist dir_hist_nosession
if [ -z $$dir_hist ] ^ /dev/null
set $dir_hist $PWD
end
set dir_hist_val (count $$dir_hist)
set -e budspencer_sessions_active_pid[$argv] ^ /dev/null
set -e budspencer_sessions_active[$argv] ^ /dev/null
set budspencer_session_current ''
cd $$dir_hist[1][$dir_hist_val]
end
set dir_hist_val (count $$dir_hist)
set -e budspencer_sessions_active_pid[$argv] ^ /dev/null
set -e budspencer_sessions_active[$argv] ^ /dev/null
set budspencer_session_current ''
cd $$dir_hist[1][$dir_hist_val]
end
function __budspencer_attach_session -d 'Attach session'
set argv (echo -sn $argv\n | sed 's|[^[:alnum:]]|_|g')
if contains $argv[1] $budspencer_sessions_active
wmctrl -a "✻ $argv[1]"
else
else
wt "✻ $argv[1]"
__budspencer_detach_session $argv[-1]
set budspencer_sessions_active $budspencer_sessions_active $argv[1]
......@@ -371,7 +381,7 @@ function __budspencer_attach_session -d 'Attach session'
end
set dir_hist_val (count $$dir_hist)
cd $$dir_hist[1][$dir_hist_val] ^ /dev/null
end
end
end
function s -d 'Create, delete or attach session'
......@@ -427,34 +437,34 @@ function s -d 'Create, delete or attach session'
case '*'
return 1
end
end
set -l item (contains -i %self $budspencer_sessions_active_pid ^ /dev/null)
switch $argv[1]
case '-e'
end
set -l item (contains -i %self $budspencer_sessions_active_pid ^ /dev/null)
switch $argv[1]
case '-e'
__budspencer_erase_session $argv
case '-d'
case '-d'
wt 'fish'
__budspencer_detach_session $item
case '-*'
case '-*'
set_color $fish_color_error[1]
echo "Invalid argument: $argv[1]"
case '*'
case '*'
__budspencer_attach_session $argv $item
end
end
end
#####################################
# => Commandline editing with $EDITOR
#####################################
function __budspencer_edit_comandline -d 'Open current commandline with your editor'
commandline > $budspencer_tmpfile
function __budspencer_edit_commandline -d 'Open current commandline with your editor'
commandline | fish_indent > $budspencer_tmpfile
eval $EDITOR $budspencer_tmpfile
if [ -s $budspencer_tmpfile ]
commandline (sed 's|^\s*||' $budspencer_tmpfile)
else
else
commandline ''
end
rm $budspencer_tmpfile
end
rm $budspencer_tmpfile
end
################
......@@ -470,9 +480,9 @@ function __budspencer_prompt_git_branch -d 'Return the current branch name'
else
echo -n (set_color -b $budspencer_colors[9])''(set_color $budspencer_colors[1])'  '$position' '(set_color $budspencer_colors[9])
end
else
else
echo -n (set_color -b $budspencer_colors[3])''(set_color $budspencer_colors[1])'  '$branch' '(set_color $budspencer_colors[3])
end
end
end
######################
......@@ -480,26 +490,26 @@ end
######################
function __budspencer_prompt_bindmode -d 'Displays the current mode'
switch $fish_bind_mode
case default
case default
set budspencer_current_bindmode_color $budspencer_colors[10]
echo -en $budspencer_cursors[1]
case insert
case insert
set budspencer_current_bindmode_color $budspencer_colors[5]
echo -en $budspencer_cursors[2]
if [ $pwd_hist_lock = true ]
if [ "$pwd_hist_lock" = true ]
set pwd_hist_lock false
__budspencer_create_dir_hist
end
case visual
case visual
set budspencer_current_bindmode_color $budspencer_colors[8]
echo -en $budspencer_cursors[3]
end
if [ (count $budspencer_prompt_error) -eq 1 ]
end
if [ (count $budspencer_prompt_error) -eq 1 ]
set budspencer_current_bindmode_color $budspencer_colors[7]
end
set_color -b $budspencer_current_bindmode_color $budspencer_colors[1]
echo -n " $pcount "
set_color -b $budspencer_colors[1] $budspencer_current_bindmode_color
end
set_color -b $budspencer_current_bindmode_color $budspencer_colors[1]
echo -n " $pcount "
set_color -b $budspencer_colors[1] $budspencer_current_bindmode_color
end
####################
......@@ -509,20 +519,20 @@ function __budspencer_prompt_left_symbols -d 'Display symbols'
set -l jobs (jobs | wc -l)
if [ -e ~/.taskrc ]
set todo (task due.before:tomorrow ^ /dev/null | tail -1 | cut -f1 -d' ')
end
if [ -e ~/.reminders ]
end
if [ -e ~/.reminders ]
set appointments (rem -a | cut -f1 -d' ')
end
if [ (count $todo) -eq 0 ]
end
if [ (count $todo) -eq 0 ]
set todo 0
end
if [ (count $appointments) -eq 0 ]
end
if [ (count $appointments) -eq 0 ]
set appointments 0
end
set_color -b $budspencer_colors[2]
echo -n ''
end
set_color -b $budspencer_colors[2]
echo -n ''
if [ $symbols_style = 'symbols' ]
if [ $symbols_style = 'symbols' ]
if [ $budspencer_session_current != '' ]
set_color -o $budspencer_colors[8]
echo -n ' ✻'
......@@ -566,7 +576,7 @@ function __budspencer_prompt_left_symbols -d 'Display symbols'
set_color -o $budspencer_colors[6]
echo -n ' ⚡'
end
else
else
if [ $budspencer_session_current != '' ] ^ /dev/null
set_color $budspencer_colors[8]
echo -n ' '(expr (count $budspencer_sessions) - (contains -i $budspencer_session_current $budspencer_sessions))
......@@ -612,9 +622,9 @@ function __budspencer_prompt_left_symbols -d 'Display symbols'
set_color -o $budspencer_colors[6]
echo -n ' ⚡'
end
end
echo -n ' '
set_color -b normal $budspencer_colors[2]
end
echo -n ' '
set_color -b normal $budspencer_colors[2]
end
###############################################################################
......@@ -669,7 +679,7 @@ if not begin
or set -q -x RANGER_LEVEL
or set -q -x VIM
end ^ /dev/null
cd $bookmarks[1]
cd $bookmarks[1]
end
set -x LOGIN $USER
......
......@@ -94,19 +94,20 @@ function __budspencer_git_status -d 'Check git status'
end
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
function __budspencer_prompt_git_symbols -d 'Displays the git symbols'
set -l is_repo (command git rev-parse --is-inside-work-tree ^/dev/null)
if [ -z $is_repo ]
return
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
[ $is_repo=true ]
[ (expr $git_status[1] + $git_status[2] + $git_status[3] + $git_status[4] + $git_status[5] + $git_status[6]) -ne 0 ]
end
if [ (expr $git_status[1] + $git_status[2] + $git_status[3] + $git_status[4] + $git_status[5] + $git_status[6] + $git_stashed) -ne 0 ]
set_color $budspencer_colors[3]
echo -n ''
set_color -b $budspencer_colors[3]
......@@ -219,7 +220,7 @@ function __budspencer_prompt_pwd -d 'Displays the present working directory'
case short
echo -n $user_host(prompt_pwd)' '
case long
echo -n $user_host$PWD' '
echo -n $user_host(pwd)' '
end
else
echo -n " $budspencer_prompt_error "
......
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