set -l readme_file "$fish_path/themes/budspencer/README.md"
if set -q PAGER
if [ -e $readme_file ]
eval $PAGER $readme_file
else
set_color $fish_color_error[1]
echo "$readme_file wasn't found."
end
else
open $readme_file
end
end
################
# => Environment
################
function day -d "Set color palette for bright environment."
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"
end
function night -d "Set color palette for dark environment."
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"
end
#################
# => Window title
#################
function wt -d 'Set window title'
set -g window_title $argv
function fish_title
echo -n $window_title
end
end
####################
# => Welcome message
####################
function fish_greeting -d 'Show greeting in login shell.'
if not set -q budspencer_nogreeting
if begin
not set -q -x LOGIN
and not set -q -x RANGER_LEVEL
and not set -q -x VIM
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 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.
set -e $cmd_hist[1][(expr $num_items - $cmd_num)] ^ /dev/null
return 0
end
return 1
end
##############
# => Bookmarks
##############
function mark -d 'Create bookmark for present working directory.'
if not contains $PWD $bookmarks
set -U bookmarks $PWD $bookmarks
set pwd_hist_lock true
commandline -f repaint
end
end
function unmark -d 'Remove bookmark for present working directory.'
if contains $PWD $bookmarks
set -e bookmarks[(contains -i $PWD $bookmarks)]
set pwd_hist_lock true
commandline -f repaint
end
end
function m -d 'List bookmarks, jump to directory in list with m <number>'
set -l num_items (count $bookmarks)
if [ $num_items -eq 0 ]
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)
if [ $PWD = $bookmarks[$i] ]
set_color $budspencer_colors[10]
else
if [ (expr \( $num_items - $i \) \% 2) -eq 0 ]
set_color normal
else
set_color $budspencer_colors[4]
end
end
echo (expr $num_items - $i)\t$bookmarks[$i] | sed "s|$HOME|~|"
end
if [ $num_items -eq 1 ]
set last_item ''
else
set last_item '-'(expr $num_items - 1)
end
echo -en $budspencer_cursors[1]
set input_length (expr length (expr $num_items - 1))
function __budspencer_delete_zombi_sessions -d 'Delete zombi sessions'
for i in $budspencer_sessions_active_pid
if not contains $i %fish
set -l item (contains -i $i $budspencer_sessions_active_pid)
set -e budspencer_sessions_active_pid[$item]
set -e budspencer_sessions_active[$item]
end
end
end
function __budspencer_create_new_session -d 'Create a new session'
set -U budspencer_session_cmd_hist_$argv[1] $$cmd_hist
set -U budspencer_session_dir_hist_$argv[1] $$dir_hist
set -U budspencer_sessions $argv[1] $budspencer_sessions
end
function __budspencer_erase_session -d 'Erase current session'
if [ (count $argv) -eq 1 ]
set_color $fish_color_error[1]
echo 'Missing argument: name of session to erase'
return
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
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
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
function __budspencer_detach_session -d 'Detach current session'
set cmd_hist cmd_hist_nosession
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
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
wt "✻ $argv[1]"
__budspencer_detach_session $argv[-1]
set budspencer_sessions_active $budspencer_sessions_active $argv[1]
set budspencer_sessions_active_pid $budspencer_sessions_active_pid %self
set budspencer_session_current $argv[1]
if not contains $argv[1] $budspencer_sessions
__budspencer_create_new_session $argv[1]
end
set cmd_hist budspencer_session_cmd_hist_$argv[1]
set dir_hist budspencer_session_dir_hist_$argv[1]
if [ -z $$dir_hist ] ^ /dev/null
set $dir_hist $PWD
end
set dir_hist_val (count $$dir_hist)
cd $$dir_hist[1][$dir_hist_val] ^ /dev/null
end
end
function s -d 'Create, delete or attach session'
__budspencer_delete_zombi_sessions
if [ (count $argv) -eq 0 ]
set -l active_indicator
set -l num_items (count $budspencer_sessions)
if [ $num_items -eq 0 ]
set_color $fish_color_error[1]
echo -n 'Session list is empty. '
set_color normal
echo -n 'Enter '
set_color $fish_color_command[1]
echo -n 's '
set_color $fish_color_param[1]
echo -n 'session-name'
set_color normal
echo ' to record the current session.'
return
end
for i in (seq $num_items)
if [ $budspencer_sessions[$i] = $budspencer_session_current ]
set_color $budspencer_colors[8]
else
if [ (expr \( $num_items - $i \) \% 2) -eq 0 ]
set_color normal
else
set_color $budspencer_colors[4]
end
end
if contains $budspencer_sessions[$i] $budspencer_sessions_active