Updated budspencer theme

Pull down menus in history functions
Readme updated
pull/2/head
Joseph 10 years ago committed by Bruno Pinto
parent bc92376da2
commit d00a7af8b4

@ -1,7 +1,20 @@
# Budspencer theme # Budspencer theme
A theme for the 70s, makes fish even more powerful. It's equipped with a few A theme for the 70s, makes fish even more powerful. It's equipped with a hell
nice functions and key bindings to speed up your workflow. of a lot of nice functions and key bindings to speed up your workflow.
The philosophy behind budspencer theme:
* Delimit the prompt lines clearly to the output.
* Produce output only if it contains relevant information.
* Show useful notifications within the prompt.
* Equip the prompt with toggle commands in order to change its style
interactively.
* Store sessions in order to make frequently used commands quickly accessible.
* Make navigation within the directory tree as easy as possible using
bookmarks and a directory history without duplicates.
* Make histories quickly accessible with menus.
* Don't stress your eyes. Use different colors in dark and bright environments.
## Demonstration video ## Demonstration video
@ -25,11 +38,12 @@ Non standard tools:
### General configuration ### General configuration
The theme behaves similar to vim's airline/powerline plugins. Thus, it needs a The theme behaves similar to vim's airline/powerline plugins. Thus, it needs a
[powerline font][font]. Although it works with emacs mode, it's more powerful [powerline font][font].
with vi mode. In order to enable vi mode, execute: It's also crucial to have vi mode enabled. Thus, execute
``` ```
set -U fish_key_bindings fish_vi_key_bindings set -U fish_key_bindings fish_vi_key_bindings
``` ```
before enabling the theme.
### Colors ### Colors
@ -88,8 +102,8 @@ set -e budspencer_nogreeting
* ⚙: there are background jobs, can be toggled with `#` to show the amount of * ⚙: there are background jobs, can be toggled with `#` to show the amount of
background jobs background jobs
* : no write permissions in present working directory * : no write permissions in present working directory
* ⚔: there are tasks scheduled due today, can be toggled with `#` to * ⚔: there are tasks scheduled for this week, can be toggled with `#` to
show the amount of tasks show the amount of weekly tasks
* ⚑: there are appointments for today, can be toggled with `#` to * ⚑: there are appointments for today, can be toggled with `#` to
show the amount of appointments show the amount of appointments
* ✔: last command succeeded, can be toggled with `#` to show the status value * ✔: last command succeeded, can be toggled with `#` to show the status value
@ -128,17 +142,24 @@ The following shortcuts need vi-mode:
`short long none`); note that changes to `$budspencer_pwdstyle` keep persistant as it's `short long none`); note that changes to `$budspencer_pwdstyle` keep persistant as it's
a universal variable. a universal variable.
![pwd style][pwdstyle]
- Style of symbols can be toggled in NORMAL and in VISUAL mode with `#` - Style of symbols can be toggled in NORMAL and in VISUAL mode with `#`
* styles implemented: * styles implemented:
- `symbols` (shows status symbols) - `symbols` (shows status symbols)
- `numbers` (shows numbers instead of symbols in left prompt as well as amount of changes in - `numbers` (shows numbers instead of symbols in left prompt as well as amount of changes in
right git prompt) right git prompt)
Note, the format is _username@hostname:pathname_. Thus, you can cut
the whole string with your mouse and paste it into `ssh` commands.
## Quickly navigate in history of working directories ## Quickly navigate in history of working directories
The function `d` shows the history as enumerated list. Unlike fish's builtin The function `d` drops down a menu showing the history as enumerated list. Unlike
`dirh`, `d` does not show any duplicates. Enter a number to jump to a directory fish's builtin `dirh`, `d` does not show any duplicates. Enter a number to jump
within the list. to a directory within the list.
![dir menu][dirmenu]
The following shortcuts need vi-mode: The following shortcuts need vi-mode:
- Press `H` in NORMAL mode to change present working directory to previous - Press `H` in NORMAL mode to change present working directory to previous
@ -148,8 +169,8 @@ The following shortcuts need vi-mode:
## Quickly navigate in command history ## Quickly navigate in command history
The function `c` shows the command history as enumerated list similarly to The function `c` drops down a menu showing the command history as enumerated list similarly to
the `d` function. Selections are also paste into the X clipboard. It's possible the `d` function. Selections are also pasted into the X clipboard. It's possible
to load a command of a former prompt by giving the prompt line number as to load a command of a former prompt by giving the prompt line number as
argument. argument.
@ -158,7 +179,8 @@ argument.
A bookmark can be created with `mark`. It can be removed with `unmark`. A bookmark can be created with `mark`. It can be removed with `unmark`.
Bookmarks are universal and thus persistant. Bookmarks are universal and thus persistant.
A new shell automatically changes working directory on startup to newest bookmark. A new shell automatically changes working directory on startup to newest bookmark.
`m` is a function that shows the bookmarks as enumerated list equivalently to `d`. `m` is a function that drops down a menu showing the bookmarks as enumerated list
equivalently to `d`.
The following shortcuts need vi mode: The following shortcuts need vi mode:
- Create a bookmark for present working directory with `m` in NORMAL mode. - Create a bookmark for present working directory with `m` in NORMAL mode.
@ -171,8 +193,7 @@ 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 or `\cv` in NORMAL/INSERT mode to edit commandline in - Type `.` in NORMAL mode to edit commandline in editor.
editor.
## Sessions ## Sessions
@ -195,6 +216,13 @@ Just type `wt <title>`.
- vi REPLACE mode, as soon as REPLACE mode is implemented within fish - vi REPLACE mode, as soon as REPLACE mode is implemented within fish
## Feedback
Give me feedback if you ...
* ... have ideas how I could improve budspencer.
* ... have problems with budspencer.
* ... have questions concerning budspencer.
[font]: https://github.com/Lokaltog/powerline-fonts [font]: https://github.com/Lokaltog/powerline-fonts
[ranger]: http://ranger.nongnu.org/ [ranger]: http://ranger.nongnu.org/
[taskwarrior]: http://taskwarrior.org/ [taskwarrior]: http://taskwarrior.org/
@ -203,3 +231,5 @@ Just type `wt <title>`.
[fish-nightly]: https://github.com/fish-shell/fish-shell/wiki/Nightly-builds [fish-nightly]: https://github.com/fish-shell/fish-shell/wiki/Nightly-builds
[screenshot]: https://raw.githubusercontent.com/tannhuber/media/master/budspencer.jpg [screenshot]: https://raw.githubusercontent.com/tannhuber/media/master/budspencer.jpg
[colors]: https://raw.githubusercontent.com/tannhuber/media/master/budspencer_replace_colors.jpg [colors]: https://raw.githubusercontent.com/tannhuber/media/master/budspencer_replace_colors.jpg
[dirmenu]: https://raw.githubusercontent.com/tannhuber/media/master/budspencer_dir_menu.jpg
[pwdstyle]: https://raw.githubusercontent.com/tannhuber/media/master/budspencer_pwd_style.jpg

@ -41,8 +41,6 @@ if [ $fish_key_bindings = 'fish_vi_key_bindings' ]
bind m mark bind m mark
bind M unmark bind M unmark
bind . __budspencer_edit_commandline bind . __budspencer_edit_commandline
bind \cv __budspencer_edit_commandline
bind -M insert \cv __budspencer_edit_commandline
bind -M insert \n __budspencer_preexec bind -M insert \n __budspencer_preexec
bind \n __budspencer_preexec bind \n __budspencer_preexec
end end
@ -69,51 +67,51 @@ function __budspencer_preexec -d 'Execute after hitting <Enter> before doing any
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
end
set -e budspencer_prompt_error[1]
if not type -q $cmd[1]
if [ -d $cmd[1] ]
set budspencer_prompt_error (cd $cmd[1] ^&1)
and commandline ''
commandline -f repaint
return return
end
set -e budspencer_prompt_error[1]
if not type -q $cmd[1]
if [ -d $cmd[1] ]
set budspencer_prompt_error (cd $cmd[1] ^&1)
and commandline ''
commandline -f repaint
return
end end
end
switch $cmd[1]
case 'c'
if begin
[ (count $cmd) -gt 1 ]
and [ $cmd[2] -gt 0 ]
and [ $cmd[2] -lt $pcount ]
end end
commandline $prompt_hist[$cmd[2]] switch $cmd[1]
echo $prompt_hist[$cmd[2]] | xsel case 'c'
commandline -f repaint if begin
return [ (count $cmd) -gt 1 ]
and [ $cmd[2] -gt 0 ]
and [ $cmd[2] -lt $pcount ]
end
commandline $prompt_hist[$cmd[2]]
echo $prompt_hist[$cmd[2]] | xsel
commandline -f repaint
return
end
case 'cd'
if [ (count $cmd) -le 2 ]
set budspencer_prompt_error (eval $cmd ^&1)
and commandline ''
if [ (count $budspencer_prompt_error) -gt 1 ]
set budspencer_prompt_error $budspencer_prompt_error[1]
end
commandline -f repaint
return
end
case 'day' 'night'
if [ (count $cmd) -eq 1 ]
eval $cmd
commandline ''
commandline -f repaint
return
end
end end
case 'cd'
if [ (count $cmd) -le 2 ]
set budspencer_prompt_error (eval $cmd ^&1)
and commandline ''
if [ (count $budspencer_prompt_error) -gt 1 ]
set budspencer_prompt_error $budspencer_prompt_error[1]
end
commandline -f repaint
return
end
case 'day' 'night'
if [ (count $cmd) -eq 1 ]
eval $cmd
commandline ''
commandline -f repaint
return
end
end end
end commandline -f execute
commandline -f execute
end end
##################### #####################
@ -131,10 +129,10 @@ function __budspencer_create_dir_hist -v PWD -d 'Create directory history withou
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
set $dir_hist $$dir_hist $PWD
set -g dir_hist_val (count $$dir_hist)
end 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.' function __budspencer_cd_prev -d 'Change to previous directory, press H in NORMAL mode.'
@ -143,7 +141,7 @@ function __budspencer_cd_prev -d 'Change to previous directory, press H in NORMA
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.'
@ -152,7 +150,7 @@ function __budspencer_cd_next -d 'Change to next directory, press L in NORMAL mo
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>'
@ -161,34 +159,39 @@ function d -d 'List directory history, jump to directory in list with d <number>
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
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 ]
set last_item ''
else else
set_color $budspencer_colors[4] set last_item '-'(expr $num_items - 1)
end end
echo (expr $num_items - $i)\t$$dir_hist[1][$i] | sed "s|$HOME|~|" echo -en $budspencer_cursors[2]
end set input_length (expr length (expr $num_items - 1))
if [ $num_items -eq 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
set last_item '' switch $dir_num
else case (seq 0 (expr $num_items - 1))
set last_item '-'(expr $num_items - 1) cd $$dir_hist[1][(expr $num_items - $dir_num)]
end case 'e'
echo -en $budspencer_cursors[2] 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 input_length (expr length (expr $num_items - 1)) set -e $dir_hist[1][(expr $num_items - $dir_num)] ^ /dev/null
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 set dir_hist_val (count $$dir_hist)
switch $dir_num tput cuu1
case (seq 0 (expr $num_items - 1)) end
cd $$dir_hist[1][(expr $num_items - $dir_num)] for i in (seq (expr $num_items + 1))
return 0 tput cuu1
case 'e' end
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 tput ed
set -e $dir_hist[1][(expr $num_items - $dir_num)] ^ /dev/null tput cuu1
set dir_hist_val (count $$dir_hist) set pcount (expr $pcount - 1)
return 0 set no_prompt_hist 'T'
end
return 1
end end
#################### ####################
@ -196,24 +199,31 @@ end
#################### ####################
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 -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 if begin
[ $pcount -gt 0 ]
and [ $no_prompt_hist = 'F' ]
end
set prompt_hist[$pcount] $cmd
else
set no_prompt_hist 'F'
end
set pcount (expr $pcount + 1)
# 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>'
@ -222,36 +232,44 @@ function c -d 'List command history, load command from prompt with c <prompt num
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
set_color $budspencer_colors[4]
end
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 ]
set last_item ''
else else
set_color $budspencer_colors[4] set last_item '-'(expr $num_items - 1)
end end
echo -n (expr $num_items - $i) echo -en $budspencer_cursors[4]
set -l item (echo $$cmd_hist[1][$i]) set input_length (expr length (expr $num_items - 1))
echo -n \t$item\n 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
end switch $cmd_num
if [ $num_items -eq 1 ] case (seq 0 (expr $num_items - 1))
set last_item '' commandline $$cmd_hist[1][(expr $num_items - $cmd_num)]
else echo $$cmd_hist[1][(expr $num_items - $cmd_num)] | xsel
set last_item '-'(expr $num_items - 1) for i in (seq (count (echo $$cmd_hist\n)))
end tput cuu1
echo -en $budspencer_cursors[4] end
set input_length (expr length (expr $num_items - 1)) case 'e'
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])" ↩ Erase [0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[9])' -n $input_length -l cmd_num
switch $cmd_num for i in (seq (count (echo $$cmd_hist\n)))
case (seq 0 (expr $num_items - 1)) tput cuu1
commandline $$cmd_hist[1][(expr $num_items - $cmd_num)] end
echo $$cmd_hist[1][(expr $num_items - $cmd_num)] | xsel tput cuu1
return 0 set -e $cmd_hist[1][(expr $num_items - $cmd_num)] ^ /dev/null
case 'e' end
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 tput ed
set -e $cmd_hist[1][(expr $num_items - $cmd_num)] ^ /dev/null tput cuu1
return 0 set pcount (expr $pcount - 1)
end set no_prompt_hist 'T'
return 1
end end
############## ##############
@ -262,7 +280,7 @@ function mark -d 'Create bookmark for present working directory.'
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.'
@ -270,7 +288,7 @@ function unmark -d 'Remove bookmark for present working directory.'
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>'
@ -279,33 +297,36 @@ function m -d 'List bookmarks, jump to directory in list with m <number>'
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
echo '▶ '(expr $num_items - $i)\t$bookmarks[$i] | sed "s|$HOME|~|"
end end
echo (expr $num_items - $i)\t$bookmarks[$i] | sed "s|$HOME|~|" if [ $num_items -eq 1 ]
end set last_item ''
if [ $num_items -eq 1 ] else
set last_item '' set last_item '-'(expr $num_items - 1)
else end
set last_item '-'(expr $num_items - 1) echo -en $budspencer_cursors[1]
end set input_length (expr length (expr $num_items - 1))
echo -en $budspencer_cursors[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
set input_length (expr length (expr $num_items - 1)) switch $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 case (seq 0 (expr $num_items - 1))
switch $dir_num cd $bookmarks[(expr $num_items - $dir_num)]
case (seq 0 (expr $num_items - 1)) end
cd $bookmarks[(expr $num_items - $dir_num)] for i in (seq (expr $num_items + 1))
return 0 tput cuu1
end end
return 1 tput ed
tput cuu1
end end
############# #############
@ -317,9 +338,9 @@ function __budspencer_delete_zombi_sessions -d 'Delete zombi sessions'
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
@ -332,20 +353,20 @@ function __budspencer_erase_session -d 'Erase current session'
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'
@ -353,35 +374,37 @@ function __budspencer_detach_session -d 'Detach current session'
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]
set no_prompt_hist 'T'
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
set dir_hist_val (count $$dir_hist)
cd $$dir_hist[1][$dir_hist_val] ^ /dev/null
end end
set dir_hist_val (count $$dir_hist) set no_prompt_hist 'T'
cd $$dir_hist[1][$dir_hist_val] ^ /dev/null
end
end end
function s -d 'Create, delete or attach session' function s -d 'Create, delete or attach session'
@ -401,70 +424,90 @@ function s -d 'Create, delete or attach session'
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
echo -en $budspencer_cursors[3]
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
set pcount (expr $pcount - 1)
switch $session_num
case (seq 0 (expr $num_items - 1))
set argv[1] $budspencer_sessions[(expr $num_items - $session_num)]
for i in (seq (expr $num_items + 1))
tput cuu1
end
tput ed
tput cuu1
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
if [ (expr $num_items - $session_num) -gt 0 ]
__budspencer_erase_session -e $budspencer_sessions[(expr $num_items - $session_num)]
end
for i in (seq (expr $num_items + 3))
tput cuu1
end
tput ed
return
case '*'
for i in (seq (expr $num_items + 1))
tput cuu1
end
tput ed
tput cuu1
return
end
end end
echo -en $budspencer_cursors[3] set -l item (contains -i %self $budspencer_sessions_active_pid ^ /dev/null)
set input_length (expr length (expr $num_items - 1)) switch $argv[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 case '-e'
switch $session_num __budspencer_erase_session $argv
case (seq 0 (expr $num_items - 1)) case '-d'
set argv[1] $budspencer_sessions[(expr $num_items - $session_num)] wt 'fish'
case 'e' __budspencer_detach_session $item
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 tput cuu1
__budspencer_erase_session -e $budspencer_sessions[(expr $num_items - $session_num)] tput ed
return 0 set pcount (expr $pcount - 1)
case '*' case '-*'
return 1 set_color $fish_color_error[1]
echo "Invalid argument: $argv[1]"
case '*'
__budspencer_attach_session $argv $item
end end
end end
set -l item (contains -i %self $budspencer_sessions_active_pid ^ /dev/null)
switch $argv[1]
case '-e'
__budspencer_erase_session $argv
case '-d'
wt 'fish'
__budspencer_detach_session $item
case '-*'
set_color $fish_color_error[1]
echo "Invalid argument: $argv[1]"
case '*'
__budspencer_attach_session $argv $item
end
end
##################################### #####################################
# => Commandline editing with $EDITOR # => Commandline editing with $EDITOR
##################################### #####################################
function __budspencer_edit_commandline -d 'Open current commandline with your editor' function __budspencer_edit_commandline -d 'Open current commandline with your editor'
commandline | fish_indent > $budspencer_tmpfile commandline > $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
################ ################
@ -475,14 +518,14 @@ function __budspencer_prompt_git_branch -d 'Return the current branch name'
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
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[9])''(set_color $budspencer_colors[1])'  '$position' '(set_color $budspencer_colors[9]) echo -n (set_color -b $budspencer_colors[3])''(set_color $budspencer_colors[1])'  '$branch' '(set_color $budspencer_colors[3])
end end
else
echo -n (set_color -b $budspencer_colors[3])''(set_color $budspencer_colors[1])'  '$branch' '(set_color $budspencer_colors[3])
end
end end
###################### ######################
@ -490,26 +533,26 @@ end
###################### ######################
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
case visual
set budspencer_current_bindmode_color $budspencer_colors[8]
echo -en $budspencer_cursors[3]
end end
case visual if [ (count $budspencer_prompt_error) -eq 1 ]
set budspencer_current_bindmode_color $budspencer_colors[8] set budspencer_current_bindmode_color $budspencer_colors[7]
echo -en $budspencer_cursors[3] end
end set_color -b $budspencer_current_bindmode_color $budspencer_colors[1]
if [ (count $budspencer_prompt_error) -eq 1 ] echo -n " $pcount "
set budspencer_current_bindmode_color $budspencer_colors[7] 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 end
#################### ####################
@ -518,113 +561,127 @@ end
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:sunday ^ /dev/null | tail -1 | cut -f1 -d' ')
end set overdue (task due.before:today ^ /dev/null | tail -1 | cut -f1 -d' ')
if [ -e ~/.reminders ]
set appointments (rem -a | cut -f1 -d' ')
end
if [ (count $todo) -eq 0 ]
set todo 0
end
if [ (count $appointments) -eq 0 ]
set appointments 0
end
set_color -b $budspencer_colors[2]
echo -n ''
if [ $symbols_style = 'symbols' ]
if [ $budspencer_session_current != '' ]
set_color -o $budspencer_colors[8]
echo -n ' ✻'
end
if contains $PWD $bookmarks
set_color -o $budspencer_colors[10]
echo -n ' ⌘'
end end
if set -q -x VIM if [ -e ~/.reminders ]
set_color -o $budspencer_colors[9] set appointments (rem -a | cut -f1 -d' ')
echo -n ' V'
end end
if set -q -x RANGER_LEVEL if [ (count $todo) -eq 0 ]
set_color -o $budspencer_colors[9] set todo 0
echo -n ' R'
end end
if [ $jobs -gt 0 ] if [ (count $overdue) -eq 0 ]
set_color -o $budspencer_colors[11] set overdue 0
echo -n ' ⚙'
end end
if [ ! -w . ] if [ (count $appointments) -eq 0 ]
set_color -o $budspencer_colors[6] set appointments 0
echo -n ' '
end end
if [ $todo -gt 0 ] set_color -b $budspencer_colors[2]
set_color -o $budspencer_colors[4] echo -n ''
echo -n ' ⚔'
end if [ $symbols_style = 'symbols' ]
if [ $appointments -gt 0 ] if [ $budspencer_session_current != '' ]
set_color -o $budspencer_colors[5] set_color -o $budspencer_colors[8]
echo -n ' ⚑' echo -n ' ✻'
end end
if [ $last_status -eq 0 ] if contains $PWD $bookmarks
set_color -o $budspencer_colors[12] set_color -o $budspencer_colors[10]
echo -n ' ✔' echo -n ' ⌘'
else end
set_color -o $budspencer_colors[7] if set -q -x VIM
echo -n ' ✘' set_color -o $budspencer_colors[9]
end echo -n ' V'
if [ $USER = 'root' ] end
set_color -o $budspencer_colors[6] if set -q -x RANGER_LEVEL
echo -n ' ⚡' set_color -o $budspencer_colors[9]
end echo -n ' R'
else end
if [ $budspencer_session_current != '' ] ^ /dev/null if [ $jobs -gt 0 ]
set_color $budspencer_colors[8] set_color -o $budspencer_colors[11]
echo -n ' '(expr (count $budspencer_sessions) - (contains -i $budspencer_session_current $budspencer_sessions)) echo -n ' ⚙'
end end
if contains $PWD $bookmarks if [ ! -w . ]
set_color $budspencer_colors[10] set_color -o $budspencer_colors[6]
echo -n ' '(expr (count $bookmarks) - (contains -i $PWD $bookmarks)) echo -n ' '
end end
if set -q -x VIM if [ $todo -gt 0 ]
set_color -o $budspencer_colors[9] set_color -o $budspencer_colors[4]
echo -n ' V' end
set_color normal if [ $overdue -gt 0 ]
end set_color -o $budspencer_colors[8]
if set -q -x RANGER_LEVEL end
set_color -b $budspencer_colors[2] $budspencer_colors[9] if [ (expr $todo + $overdue) -gt 0 ]
echo -n ' '$RANGER_LEVEL echo -n ' ⚔'
end end
if [ $jobs -gt 0 ] if [ $appointments -gt 0 ]
set_color -b $budspencer_colors[2] $budspencer_colors[11] set_color -o $budspencer_colors[5]
echo -n ' '$jobs echo -n ' ⚑'
end end
if [ ! -w . ] if [ $last_status -eq 0 ]
set_color -o $budspencer_colors[6] set_color -o $budspencer_colors[12]
echo -n ' ' echo -n ' ✔'
set_color normal else
end set_color -o $budspencer_colors[7]
if [ $todo -gt 0 ] echo -n ' ✘'
set_color -b $budspencer_colors[2] $budspencer_colors[4] end
echo -n " $todo" if [ $USER = 'root' ]
end set_color -o $budspencer_colors[6]
if [ $appointments -gt 0 ] echo -n ' ⚡'
set_color -b $budspencer_colors[2] $budspencer_colors[5] end
echo -n " $appointments"
end
if [ $last_status -eq 0 ]
set_color -b $budspencer_colors[2] $budspencer_colors[12]
echo -n ' '$last_status
else else
set_color -b $budspencer_colors[2] $budspencer_colors[7] if [ $budspencer_session_current != '' ] ^ /dev/null
echo -n ' '$last_status set_color $budspencer_colors[8]
end echo -n ' '(expr (count $budspencer_sessions) - (contains -i $budspencer_session_current $budspencer_sessions))
if [ $USER = 'root' ] end
set_color -o $budspencer_colors[6] if contains $PWD $bookmarks
echo -n ' ⚡' set_color $budspencer_colors[10]
echo -n ' '(expr (count $bookmarks) - (contains -i $PWD $bookmarks))
end
if set -q -x VIM
set_color -o $budspencer_colors[9]
echo -n ' V'
set_color normal
end
if set -q -x RANGER_LEVEL
set_color -b $budspencer_colors[2] $budspencer_colors[9]
echo -n ' '$RANGER_LEVEL
end
if [ $jobs -gt 0 ]
set_color -b $budspencer_colors[2] $budspencer_colors[11]
echo -n ' '$jobs
end
if [ ! -w . ]
set_color -o $budspencer_colors[6]
echo -n ' '
set_color normal
end
if [ $todo -gt 0 ]
set_color -b $budspencer_colors[2] $budspencer_colors[4]
end
if [ $overdue -gt 0 ]
set_color -b $budspencer_colors[2] $budspencer_colors[8]
end
if [ (expr $todo + $overdue) -gt 0 ]
echo -n " $todo"
end
if [ $appointments -gt 0 ]
set_color -b $budspencer_colors[2] $budspencer_colors[5]
echo -n " $appointments"
end
if [ $last_status -eq 0 ]
set_color -b $budspencer_colors[2] $budspencer_colors[12]
echo -n ' '$last_status
else
set_color -b $budspencer_colors[2] $budspencer_colors[7]
echo -n ' '$last_status
end
if [ $USER = 'root' ]
set_color -o $budspencer_colors[6]
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
############################################################################### ###############################################################################
@ -645,6 +702,7 @@ set -g dir_hist dir_hist_nosession
set -g pwd_hist_lock false set -g pwd_hist_lock false
set -g pcount 1 set -g pcount 1
set -g prompt_hist set -g prompt_hist
set -g no_prompt_hist 'F'
set -g symbols_style 'symbols' set -g symbols_style 'symbols'
# Load user defined key bindings # Load user defined key bindings
@ -675,11 +733,11 @@ 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

Loading…
Cancel
Save