Budspencer theme improvements

- prompt line enumeration implemented
- new function to set the window title
- new session history
- README file updated
- replaced all `math` commands by `expr` for better performance
This commit is contained in:
Joseph Tannhuber 2014-09-06 22:08:09 +02:00 committed by Bruno Pinto
parent b0977db783
commit 3649ca3b38
4 changed files with 937 additions and 625 deletions

View File

@ -1,32 +1,86 @@
# budspencer theme # Budspencer theme
Translation of zsh's prezto [budspencer theme][budspencer]. This theme is A theme for the 70s, makes fish even more powerful. It's equipped with a few
optimized for visibility and a fast workflow. nice functions and key bindings to speed up your workflow.
## Demonstration video
[![video][screenshot]](http://vimeo.com/105546618)
## Requirements ## Requirements
You need an up-to-date fish shell version from [github][fish-git] or a
[nightly build][fish-nightly].
Non standard tools: Non standard tools:
* xsel * xsel
* wmctrl
* git * git
* [taskwarrior][taskwarrior] (optional)
* [remind][remind] (optional)
## Configuration ## 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]. Although it works with emacs mode, it's more powerful
with vi mode. In order to enable vi mode, put the following lines into with vi mode. In order to enable vi mode, execute:
`$HOME/.config/fish/config.fish` before `set fish_path $HOME/.oh-my-fish`:
``` ```
set -U fish_key_bindings fish_vi_key_bindings set -U fish_key_bindings fish_vi_key_bindings
``` ```
### Colors
Redefine `$budspencer_colors` with the `set` command in order to change the
colors of the prompt.
Example:
```
set budspencer_colors 000000 333333 666666 ffffff ffff00 ff6600 ff0000 ff0033 3300ff 0000ff 00ffff
00ff00
```
will result in a prompt like this:
![color replace example][colors]
Two color schemes for bright and dark environments are predefined. You can
enable them with `day` and `night`, respectively.
### Command history
Commands that shouldn't appear in the command history are defined by a universal
list `$budspencer_nocmdhist`. Default:
```
set -U budspencer_nocmdhist c d ll ls m s
```
### Disable/reenable greeting
Disable:
```
set -U budspencer_nogreeting
```
Reenable:
```
set -e budspencer_nogreeting
```
## Outer prompt segments
- Vi mode is indicated by color of outer segments, cursor color also changes
if terminal supports it:
* blue: NORMAL mode
* yellow: INSERT mode
* magenta: VISUAL mode
## Left prompt segments ## Left prompt segments
- Vi mode indicator similar to vim airline/powerline, cursor color also changes - Prompt line number
if terminal supports it
- Git repository information - Git repository information
- Status symbols - Status symbols
* ✻: keep track of this shell session, can be toggled with `#` to show the number of
the session within the sessions list
* ⌘: present working directory is in bookmark list, can be toggled with `#` to * ⌘: present working directory is in bookmark list, can be toggled with `#` to
show the number of the bookmark show the number of the bookmark
* V: vi is parent process * V: vi is parent process
@ -34,6 +88,10 @@ set -U fish_key_bindings fish_vi_key_bindings
* ⚙: 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
show the amount of tasks
* ⚑: there are appointments for today, can be toggled with `#` to
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
* ✘: last command failed, can be toggled with `#` to show the status value * ✘: last command failed, can be toggled with `#` to show the status value
* ⚡: superuser indicator * ⚡: superuser indicator
@ -42,17 +100,16 @@ set -U fish_key_bindings fish_vi_key_bindings
## Right prompt segments ## Right prompt segments
- Last command's duration time - Last command's duration time
- Git status - Git status symbols:
* symbols: * ↑: git repository is ahead origin
- ↑: git repository is ahead origin * ↓: git repository is behind origin
- ↓: git repository is behind origin * +: changes have been added to git index
- +: changes have been added to git index * : files have been deleted in work tree
- : files have been deleted in work tree * ✱: files have been modified in work tree
- ✱: files have been modified in work tree * →: files have been renamed in git index
- →: files have been renamed in git index * ═: there are unmerged commits
- ═: there are unmerged commits * ●: there are untracked (new) files
- ●: there are untracked (new) files * ✭: there are stashed commits
- ✭: there are stashed commits
## Toggle prompt segments ## Toggle prompt segments
@ -67,10 +124,9 @@ The following shortcuts need vi-mode:
- `none` (shows nothing except small delimiter; useful for small terminals) - `none` (shows nothing except small delimiter; useful for small terminals)
- If prompt is toggled with `#`, the IP address is shown instead of the - If prompt is toggled with `#`, the IP address is shown instead of the
hostname. hostname.
* configurable by global list `$PWDSTYLE` (if not set, defaults to * configurable by universal list `$budspencer_pwdstyle` (if not set, defaults to
`short long none`); put `set -g PWDSTYLE none long` into `short long none`); note that changes to `$budspencer_pwdstyle` keep persistant as it's
`$HOME/.config/fish/budspencer_config.fish` if you want to toggle only between a universal variable.
`none` and `long`.
- 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:
@ -80,10 +136,9 @@ The following shortcuts need vi-mode:
## Quickly navigate in history of working directories ## Quickly navigate in history of working directories
There is a function `d` that shows the history as enumerated list. Unlike The function `d` shows the history as enumerated list. Unlike fish's builtin
fish's builtin `dirh`, `d` does not show any duplicates. Enter a number to jump `dirh`, `d` does not show any duplicates. Enter a number to jump to a directory
to a directory within the list. It's also possible to give that number directly as within the list.
argument to the `d` function.
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
@ -93,14 +148,15 @@ 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 equivalently to The function `c` shows the command history as enumerated list similarly to
the `d` function. Selections are also paste into the X clipboard. the `d` function. Selections are also paste into the X clipboard. It's possible
to load a command of a former prompt by giving the prompt line number as
argument.
## Bookmarks ## Bookmarks
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 persistent and universal. Bookmarks are universal and thus persistant.
They are stored in `$HOME/.config/fish/budspencer_config.fish`.
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 shows the bookmarks as enumerated list equivalently to `d`.
@ -111,21 +167,38 @@ The following shortcuts need vi mode:
## Edit commandline with your favorite editor ## Edit commandline with your favorite editor
The function `edit-commandline` let you edit the commandline with your editor. The function `edit-commandline` let you edit the commandline with your editor.
It makes your commandline as powerful as your editor. If `$EDITOR` is not set, It makes the commandline as powerful as your editor. If `$EDITOR` is not set,
use vi. 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 to edit commandline in editor.
## Screenshot ## Sessions
![budspencer theme][screenshot] Shell session can be stored with `s <session name>`. If a session with `session
name` already exists, the session with this name will be attached. If a session with
`session name` is already active within another terminal, this terminal will be
focussed.
A list of available sessions can be shown with `s`.
A session can be erased with `s -e <session name>`.
Type `s -d` to detach current session.
## Set window title
Just type `wt <title>`.
## TODO ## TODO
- vi REPLACE mode, as soon as REPLACE mode is implemented within fish - vi REPLACE mode, as soon as REPLACE mode is implemented within fish
[budspencer]: https://github.com/tannhuber/prezto
[font]: https://github.com/Lokaltog/powerline-fonts [font]: https://github.com/Lokaltog/powerline-fonts
[ranger]: http://ranger.nongnu.org/ [ranger]: http://ranger.nongnu.org/
[screenshot]: https://raw.githubusercontent.com/tannhuber/prezto/master/screenshots/budspencer.png [taskwarrior]: http://taskwarrior.org/
[remind]: http://www.roaringpenguin.com/products/remind
[fish-git]: https://github.com/fish-shell/fish-shell.git
[fish-nightly]: https://github.com/fish-shell/fish-shell/wiki/Nightly-builds
[screenshot]: https://raw.githubusercontent.com/tannhuber/media/master/budspencer.jpg
[colors]: https://raw.githubusercontent.com/tannhuber/media/master/budspencer_replace_colors.jpg

View File

@ -1,21 +1,46 @@
############################################################################### ###############################################################################
# #
# Prompt theme name: # prompt theme name:
# budspencer # budspencer
# #
# Description: # description:
# a sophisticated airline/powerline theme # a sophisticated airline/powerline theme
# #
# Author: # author:
# Joseph Tannhuber <sepp.tannhuber@yahoo.de> # joseph tannhuber <sepp.tannhuber@yahoo.de>
# #
# Sections: # sections:
# -> Color definitions
# -> Functions # -> Functions
# -> Help # -> Help
# -> Environment
# -> Window title
# -> Welcome message # -> Welcome message
# #
############################################################################### ###############################################################################
###############################################################################
# => Color definitions
###############################################################################
# Define colors
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
if not set -q budspencer_colors
# Values are: black dark_gray light_gray white yellow orange red magenta violet blue cyan green
set -U budspencer_colors $budspencer_night
end
# Cursor color changes according to vi-mode
# Define values for: normal_mode insert_mode visual_mode
set -U 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"
# Some terminals cannot change the cursor color
set -l unsupported_terminals 'fbterm' 'st' 'linux' 'screen'
if contains $TERM $unsupported_terminals
set budspencer_cursors '' '' '' ''
end
############################################################################### ###############################################################################
# => Functions # => Functions
############################################################################### ###############################################################################
@ -23,32 +48,55 @@
######### #########
# => Help # => Help
######### #########
function budspencer_help -d "Shows 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 test -e $readme_file if [ -e $readme_file ]
eval $PAGER $readme_file eval $PAGER $readme_file
else else
set_color $fish_color_error 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
################
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 # => 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 begin if begin
test (count $bookmarks) -gt 0 not set -q -x LOGIN
and 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 oh-my-fish\'s (set_color -b 083746 268bd2)budspencer(set_color normal) theme. 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 083746 cb4b16)»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.
set_color normal end
end end
end end

View File

@ -10,55 +10,39 @@
# Joseph Tannhuber <sepp.tannhuber@yahoo.de> # Joseph Tannhuber <sepp.tannhuber@yahoo.de>
# #
# Sections: # Sections:
# -> Color definitions
# -> Key bindings # -> Key bindings
# -> Files # -> Files
# -> Functions # -> Functions
# -> Pre execute
# -> Directory history # -> Directory history
# -> Command history # -> Command history
# -> Bookmarks # -> Bookmarks
# -> Sessions
# -> Commandline editing with $EDITOR # -> Commandline editing with $EDITOR
# -> Git segment # -> Git segment
# -> Bind-mode segment # -> Bind-mode segment
# -> Symbols segment # -> Symbols segment
# -> Prompt initialization # -> Prompt initialization
# -> Left prompt # -> Left prompt
# -> Segments
# #
############################################################################### ###############################################################################
###############################################################################
# => Color definitions
###############################################################################
# Define colors
# Values are: black dark_gray light_gray white yellow orange red magenta violet blue cyan green
set -g budspencer_colors 000000 083743 445659 fdf6e3 b58900 cb4b16 dc121f af005f 6c71c4 268bd2 2aa198 859900
# Cursor color changes according to vi-mode
# Define values for: normal_mode insert_mode visual_mode
set -g budspencer_cursors "\033]12;#$budspencer_colors[10]\007" "\033]12;#$budspencer_colors[5]\007" "\033]12;#$budspencer_colors[8]\007"
# Some terminals cannot change the cursor color
set -l unsupported_terminals "fbterm" "st" "linux" "screen"
if contains $TERM $unsupported_terminals
set -e budspencer_cursors
end
############################################################################### ###############################################################################
# => Key bindings # => Key bindings
############################################################################### ###############################################################################
if test "$fish_key_bindings" = "fish_vi_key_bindings" if [ $fish_key_bindings = 'fish_vi_key_bindings' ]
bind '#' fish_symbols_toggle_cm bind '#' __budspencer_toggle_symbols
bind -M visual '#' fish_symbols_toggle_cm bind -M visual '#' __budspencer_toggle_symbols
bind ' ' fish_pwd_toggle_cm bind ' ' __budspencer_toggle_pwd
bind -M visual ' ' fish_pwd_toggle_cm bind -M visual ' ' __budspencer_toggle_pwd
bind L fish_cd_next bind L __budspencer_cd_next
bind H fish_cd_prev bind H __budspencer_cd_prev
bind m mark bind m mark
bind M unmark bind M unmark
bind . edit-commandline bind . __budspencer_edit_comandline
bind -M insert \n __budspencer_preexec
bind \n __budspencer_preexec
end end
############################################################################### ###############################################################################
@ -66,210 +50,409 @@ end
############################################################################### ###############################################################################
# Config file # Config file
set -g budspencer_config $HOME/.config/fish/budspencer_config.fish set -g budspencer_config "$HOME/.config/fish/budspencer_config.fish"
# Temporary file # Temporary files
set -g budspencer_tmpfile "/tmp/"(echo %self)".fish" set -g budspencer_tmpfile '/tmp/'(echo %self)'_budspencer_edit.fish'
############################################################################### ###############################################################################
# => Functions # => Functions
############################################################################### ###############################################################################
################
# => Pre execute
################
function __budspencer_preexec -d 'Execute after hitting <Enter> before doing anything else'
set -l cmd (commandline | sed 's|\s\+|\x1e|g')
if [ $_ = 'fish' ]
if [ -z $cmd[1] ]
set -e cmd[1]
end
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
end
end
switch $cmd[1]
case 'c'
if begin
[ (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
commandline -f execute
end
###################### ######################
# => Directory history # => Directory history
###################### ######################
function 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 test $hist_lock = "false" if [ $pwd_hist_lock = false ]
if contains $PWD $dir_hist if contains $PWD $$dir_hist
set -e dir_hist[(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 fish_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 test $dir_hist_val -gt 1 if [ $dir_hist_val -gt 1 ]
set dir_hist_val (math $dir_hist_val-1) set dir_hist_val (expr $dir_hist_val - 1)
set hist_lock "true" set pwd_hist_lock true
cd $dir_hist[$dir_hist_val] cd $$dir_hist[1][$dir_hist_val]
commandline -f repaint commandline -f repaint
end end
end end
function fish_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 test $dir_hist_val -lt (math (count $dir_hist)) if [ $dir_hist_val -lt (count $$dir_hist) ]
set dir_hist_val (math $dir_hist_val+1) set dir_hist_val (expr $dir_hist_val + 1)
set hist_lock "true" set pwd_hist_lock true
cd $dir_hist[$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 hist_lock "true" set -l num_items (expr (count $$dir_hist) - 1)
set -l num_items (math (count $dir_hist)-1) if [ $num_items -eq 0 ]
if test $num_items -eq 0 set_color $fish_color_error[1]
echo (set_color $fish_color_error)"Directory history is empty." echo 'Directory history is empty. '(set_color normal)'It will be created automatically'
return return
end end
if test $argv[1] -ge 0 -a $argv[1] -lt $num_items ^ /dev/null
cd $dir_hist[(math $num_items-$argv[1])]
else
for i in (seq $num_items) for i in (seq $num_items)
if test (math \($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 (math $num_items-$i)\t$dir_hist[$i] | sed "s|$HOME|~|" echo (expr $num_items - $i)\t$$dir_hist[1][$i] | sed "s|$HOME|~|"
end end
if test $num_items -eq 1 if [ $num_items -eq 1 ]
set last_item "" set last_item ''
else else
set last_item "-"(math $num_items-1) set last_item '-'(expr $num_items - 1)
end end
set input_length (expr length (math $num_items-1)) echo -en $budspencer_cursors[2]
read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[5])" ♻ Goto [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))
if begin 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
test -n $dir_num switch $dir_num
and contains $dir_num (seq 0 (math $num_items-1)) case (seq 0 (expr $num_items - 1))
cd $$dir_hist[1][(expr $num_items - $dir_num)]
return 0
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 end
cd $dir_hist[(math $num_items-$dir_num)] return 1
end
end
end end
#################### ####################
# => Command history # => Command history
#################### ####################
function 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 test $hist_lock = "false" if [ $_ = 'fish' ]
set -l cmd $history[1] set pcount (expr $pcount + 1)
set -l IFS ''
set -l cmd (echo $history[1] | fish_indent | expand -t 4)
# Create prompt history
set prompt_hist $prompt_hist $cmd
# Create command history
if not begin if not begin
expr $cmd : 'cd ' > /dev/null expr $cmd : '[cdms] ' > /dev/null
or expr $cmd : '[cdm] ' > /dev/null or contains $cmd $budspencer_nocmdhist
or test $cmd = 'cd' -o $cmd = 'c' -o $cmd = 'd' -o $cmd = 'm'
end end
if contains $cmd $cmd_hist if contains $cmd $$cmd_hist
set -e cmd_hist[(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
echo -n \a
end end
function c -d "List command history, execute command in list with c <number>" function c -d 'List command history, load command from prompt with c <prompt number>'
set hist_lock "true" set -l num_items (count $$cmd_hist)
set -l num_items (count $cmd_hist) if [ $num_items -eq 0 ]
if test $num_items -eq 0 set_color $fish_color_error[1]
echo (set_color $fish_color_error)"Command history is empty." echo 'Command history is empty. '(set_color normal)'It will be created automatically.'
return return
end end
if test $argv[1] -lt $num_items ^ /dev/null
commandline $cmd_hist[(math $num_items-$argv[1])]
echo $cmd_hist[(math $num_items-$argv[1])] | xsel
else
for i in (seq $num_items) for i in (seq $num_items)
if test (math \($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 (math $num_items-$i) echo -n (expr $num_items - $i)
set -l item (echo $cmd_hist[$i] | fish_indent | expand -t 4) set -l item (echo $$cmd_hist[1][$i])
echo -n \t$item\n echo -n \t$item\n
end end
if test $num_items -eq 1 if [ $num_items -eq 1 ]
set last_item "" set last_item ''
else else
set last_item "-"(math $num_items-1) set last_item '-'(expr $num_items - 1)
end end
set input_length (expr length (math $num_items-1)) echo -en $budspencer_cursors[4]
read -p 'echo -n (set_color -b $budspencer_colors[2] $budspencer_colors[8])" ↩ Exec [0"$last_item"] "(set_color -b normal $budspencer_colors[2])" "(set_color $budspencer_colors[8])' -n $input_length -l cmd_num set input_length (expr length (expr $num_items - 1))
if begin 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
test -n $cmd_num switch $cmd_num
and contains $cmd_num (seq 0 (math $num_items-1)) 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'
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 end
commandline $cmd_hist[(math $num_items-$cmd_num)] return 1
echo $cmd_hist[(math $num_items-$cmd_num)] | xsel
end
set fish_bind_mode default
end
set hist_lock "false"
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
sed -i '/^set -U bookmarks/d' $budspencer_config ^ /dev/null set pwd_hist_lock true
echo "set -U bookmarks $bookmarks" >> $budspencer_config
set 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)]
sed -i '/^set -U bookmarks/d' $budspencer_config ^ /dev/null set pwd_hist_lock true
echo "set -U bookmarks $bookmarks" >> $budspencer_config
set 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 hist_lock "true"
set -l num_items (count $bookmarks) set -l num_items (count $bookmarks)
if test $num_items -eq 0 if [ $num_items -eq 0 ]
echo (set_color $fish_color_error)"Bookmark list is empty." 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 return
end end
if test $argv[1] -ge 0 -a $argv[1] -lt $num_items ^ /dev/null
cd $bookmarks[(math $num_items-$argv[1])]
else
for i in (seq $num_items) for i in (seq $num_items)
if test (math \($num_items-$i\)%2) -eq 0 if [ $PWD = $bookmarks[$i] ]
set_color $budspencer_colors[10]
else
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 (math $num_items-$i)\t$bookmarks[$i] | sed "s|$HOME|~|"
end end
if test $num_items -eq 1 echo (expr $num_items - $i)\t$bookmarks[$i] | sed "s|$HOME|~|"
set last_item "" end
if [ $num_items -eq 1 ]
set last_item ''
else else
set last_item "-"(math $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 $num_items) 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
case (seq 0 (expr $num_items - 1))
cd $bookmarks[(expr $num_items - $dir_num)]
return 0
end
return 1
end
if begin #############
test -n $dir_num # => Sessions
and contains $dir_num (seq 0 (math $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
cd $bookmarks[(math $num_items-$dir_num)]
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
set active_indicator '✻ '
else
set active_indicator ' '
end
echo (expr $num_items - $i)\t$active_indicator$budspencer_sessions[$i]
end
if [ $num_items -eq 1 ]
set last_item ''
else
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
switch $session_num
case (seq 0 (expr $num_items - 1))
set argv[1] $budspencer_sessions[(expr $num_items - $session_num)]
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
__budspencer_erase_session -e $budspencer_sessions[(expr $num_items - $session_num)]
return 0
case '*'
return 1
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
end end
##################################### #####################################
# => Commandline editing with $EDITOR # => Commandline editing with $EDITOR
##################################### #####################################
function edit-commandline -d "Opens current commandline with your $EDITOR" function __budspencer_edit_comandline -d 'Open current commandline with your editor'
commandline > $budspencer_tmpfile commandline > $budspencer_tmpfile
eval $EDITOR $budspencer_tmpfile eval $EDITOR $budspencer_tmpfile
if test -s $budspencer_tmpfile if [ -s $budspencer_tmpfile ]
set hist_lock "true"
commandline (sed 's|^\s*||' $budspencer_tmpfile) commandline (sed 's|^\s*||' $budspencer_tmpfile)
else else
set hist_lock "true" commandline ''
commandline ""
end end
rm $budspencer_tmpfile rm $budspencer_tmpfile
end end
@ -277,128 +460,160 @@ 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 test (count $branch) -eq 0 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 test (count $position) -eq 0 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_color -b $budspencer_colors[10] $budspencer_colors[1] set budspencer_current_bindmode_color $budspencer_colors[10]
echo -en $budspencer_cursors[1] echo -en $budspencer_cursors[1]
if test "$fish_key_bindings" = "fish_vi_key_bindings" -o "$fish_key_bindings" = "fish_user_key_bindings"
echo -n " NORMAL "
else
echo -n " EMACS "
end
set_color -b $budspencer_colors[1] $budspencer_colors[10]
case insert case insert
set_color -b $budspencer_colors[5] $budspencer_colors[1] set budspencer_current_bindmode_color $budspencer_colors[5]
echo -en $budspencer_cursors[2] echo -en $budspencer_cursors[2]
echo -n " INSERT " if [ $pwd_hist_lock = true ]
set_color -b $budspencer_colors[1] $budspencer_colors[5] set pwd_hist_lock false
if test $hist_lock = "true" __budspencer_create_dir_hist
set hist_lock "false"
create_dir_hist
end end
case visual case visual
set_color -b $budspencer_colors[8] $budspencer_colors[1] set budspencer_current_bindmode_color $budspencer_colors[8]
echo -en $budspencer_cursors[3] echo -en $budspencer_cursors[3]
echo -n " VISUAL "
set_color -b $budspencer_colors[1] $budspencer_colors[8]
end 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 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)
if [ -e ~/.taskrc ]
set todo (task due.before:tomorrow ^ /dev/null | tail -1 | cut -f1 -d' ')
end
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] set_color -b $budspencer_colors[2]
echo -n "" echo -n ''
# Bookmark indicator if [ $symbols_style = 'symbols' ]
if [ $budspencer_session_current != '' ]
set_color -o $budspencer_colors[8]
echo -n ' ✻'
end
if contains $PWD $bookmarks if contains $PWD $bookmarks
if test $symbols_style = "symbols"
set_color -o $budspencer_colors[10] set_color -o $budspencer_colors[10]
echo -n " ⌘" echo -n ' ⌘'
else
set_color $budspencer_colors[10]
echo -n " "(math (count $bookmarks)-(contains -i $PWD $bookmarks))
end end
end
# Indicator for vim parent process
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
# Indicator for ranger parent process
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
# Background job indicator
set jobs (jobs | wc -l)
if [ $jobs -gt 0 ] if [ $jobs -gt 0 ]
if test $symbols_style = "symbols"
set_color -o $budspencer_colors[11] set_color -o $budspencer_colors[11]
echo -n " ⚙" echo -n ' ⚙'
else
set_color normal
set_color -b $budspencer_colors[2] $budspencer_colors[11]
echo -n " "$jobs
end end
end
# Write protection indicator
if [ ! -w . ] if [ ! -w . ]
set_color -o $budspencer_colors[6] set_color -o $budspencer_colors[6]
echo -n " " echo -n ' '
end
if [ $todo -gt 0 ]
set_color -o $budspencer_colors[4]
echo -n ' ⚔'
end
if [ $appointments -gt 0 ]
set_color -o $budspencer_colors[5]
echo -n ' ⚑'
end end
# Status indicator
if [ $last_status -eq 0 ] if [ $last_status -eq 0 ]
if test $symbols_style = "symbols"
set_color -o $budspencer_colors[12] set_color -o $budspencer_colors[12]
echo -n " ✔" echo -n ' ✔'
else else
set_color normal
set_color -b $budspencer_colors[2] $budspencer_colors[12]
echo -n " "$last_status
end
else
if test $symbols_style = "symbols"
set_color -o $budspencer_colors[7] set_color -o $budspencer_colors[7]
echo -n " ✘" echo -n ' ✘'
else
set_color normal
set_color -b $budspencer_colors[2] $budspencer_colors[7]
echo -n " "$last_status
end end
end if [ $USER = 'root' ]
# Superuser indicator
if [ $USER = "root" ]
set_color -o $budspencer_colors[6] set_color -o $budspencer_colors[6]
echo -n " ⚡" echo -n ' ⚡'
end end
echo -n " " 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))
end
if contains $PWD $bookmarks
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]
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
echo -n ' '
set_color -b normal $budspencer_colors[2] set_color -b normal $budspencer_colors[2]
end end
@ -407,10 +622,20 @@ end
############################################################################### ###############################################################################
# Initialize some global variables # Initialize some global variables
set -g hist_lock false set -g budspencer_prompt_error
set -g dir_hist set -g budspencer_current_bindmode_color
set -g cmd_hist set -U budspencer_sessions_active $budspencer_sessions_active
set -U budspencer_sessions_active_pid $budspencer_sessions_active_pid
set -g budspencer_session_current ''
set -g cmd_hist_nosession
set -g cmd_hist cmd_hist_nosession
set -g CMD_DURATION 0 set -g CMD_DURATION 0
set -g dir_hist_nosession
set -g dir_hist dir_hist_nosession
set -g pwd_hist_lock false
set -g pcount 1
set -g prompt_hist
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
@ -423,15 +648,20 @@ if not set -q EDITOR
end end
# Source config file # Source config file
if test -e $budspencer_config if [ -e $budspencer_config ]
source $budspencer_config source $budspencer_config
end end
# Set PWD segment style # Don't save in command history
if set -q $PWDSTYLE if not set -q budspencer_nocmdhist
set -g PWDSTYLE short long none set -U budspencer_nocmdhist 'c' 'd' 'll' 'ls' 'm' 's'
end end
set pwd_style $PWDSTYLE[1]
# Set PWD segment style
if not set -q budspencer_pwdstyle
set -U budspencer_pwdstyle short long none
end
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
@ -447,27 +677,7 @@ set -x LOGIN $USER
# => Left prompt # => Left prompt
############################################################################### ###############################################################################
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) '' ' '
#############
# => Segments
#############
# Vi mode
set -l ps_vi ""
set ps_vi (__budspencer_prompt_bindmode)
# Git
set -l ps_git ""
set -l git_branch_name (__budspencer_prompt_git_branch)
if test -n "$git_branch_name"
set ps_git $git_branch_name
end
# Symbols
set -l ps_symbols (__budspencer_prompt_left_symbols)
# Left prompt
echo -n -s $ps_vi $ps_git $ps_symbols '' ' '
end end

View File

@ -16,7 +16,6 @@
# -> Git segment # -> Git segment
# -> PWD segment # -> PWD segment
# -> Prompt # -> Prompt
# -> Segments
# #
############################################################################### ###############################################################################
@ -27,22 +26,21 @@
##################### #####################
# => Toggle functions # => Toggle functions
##################### #####################
set symbols_style "symbols" function __budspencer_toggle_symbols -d 'Toggles style of symbols, press # in NORMAL or VISUAL mode'
function fish_symbols_toggle_cm -d "Toggles style of symbols, press # in NORMAL or VISUAL mode" if [ $symbols_style = 'symbols' ]
if test $symbols_style = "symbols" set symbols_style 'numbers'
set symbols_style "numbers"
else else
set symbols_style "symbols" set symbols_style 'symbols'
end end
set hist_lock "true" set pwd_hist_lock true
commandline -f repaint commandline -f repaint
end end
function fish_pwd_toggle_cm -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 $PWDSTYLE)) for i in (seq (count $budspencer_pwdstyle))
if test $PWDSTYLE[$i] = $pwd_style if [ $budspencer_pwdstyle[$i] = $pwd_style ]
set pwd_style $PWDSTYLE[(math $i%(count $PWDSTYLE)+1)] set pwd_style $budspencer_pwdstyle[(expr $i \% (count $budspencer_pwdstyle) + 1)]
set hist_lock "true" set pwd_hist_lock true
commandline -f repaint commandline -f repaint
break break
end end
@ -52,27 +50,27 @@ end
############################# #############################
# => Command duration segment # => Command duration segment
############################# #############################
function fish_cmd_duration_cm -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 (math $CMD_DURATION/1000) set -l cmd_duration (expr $CMD_DURATION / 1000)
if test $cmd_duration -gt 0 if [ $cmd_duration -gt 0 ]
set seconds (math $cmd_duration%68400%3600%60)"s" set seconds (expr $cmd_duration \% 68400 \% 3600 \% 60)'s'
if test $cmd_duration -ge 60 if [ $cmd_duration -ge 60 ]
set minutes (math $cmd_duration%68400%3600/60)"m" set minutes (expr $cmd_duration \% 68400 \% 3600 / 60)'m'
if test $cmd_duration -ge 3600 if [ $cmd_duration -ge 3600 ]
set hours (math $cmd_duration%68400/3600)"h" set hours (expr $cmd_duration \% 68400 / 3600)'h'
if test $cmd_duration -ge 68400 if [ $cmd_duration -ge 68400 ]
set days (math $cmd_duration/68400)"d" set days (expr $cmd_duration / 68400)'d'
end end
end end
end end
if test $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
@ -80,11 +78,11 @@ 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")
@ -95,136 +93,138 @@ function __budspencer_git_status -d "Check git status"
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 stash list ^ /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 git_prompt ""
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)
if test $is_repo="true"
set -l git_ahead_behind (__budspencer_is_git_ahead_or_behind) set -l git_ahead_behind (__budspencer_is_git_ahead_or_behind)
if test (count $git_ahead_behind) -eq 2
if test $git_ahead_behind[1] -gt 0
if test $symbols_style = "symbols"
set git_prompt (set_color -o $budspencer_colors[5])" ↑"
else
set git_prompt (set_color $budspencer_colors[5])" "$git_ahead_behind[1]
end
end
if test $git_ahead_behind[2] -gt 0
if test $symbols_style = "symbols"
set git_prompt $git_prompt(set_color -o $budspencer_colors[5])" ↓"
else
set git_prompt $git_prompt(set_color $budspencer_colors[5])" "$git_ahead_behind[2]
end
end
end
set -l git_status (__budspencer_git_status) set -l git_status (__budspencer_git_status)
if test $git_status[1] -gt 0
if test $symbols_style = "symbols"
set git_prompt $git_prompt(set_color -o $budspencer_colors[12])" +"
else
set git_prompt $git_prompt(set_color $budspencer_colors[12])" "$git_status[1]
end
end
if test $git_status[2] -gt 0
if test $symbols_style = "symbols"
set git_prompt $git_prompt(set_color -o $budspencer_colors[7])" "
else
set git_prompt $git_prompt(set_color $budspencer_colors[7])" "$git_status[2]
end
end
if test $git_status[3] -gt 0
if test $symbols_style = "symbols"
set git_prompt $git_prompt(set_color -o $budspencer_colors[10])" ✱"
else
set git_prompt $git_prompt(set_color $budspencer_colors[10])" "$git_status[3]
end
end
if test $git_status[4] -gt 0
if test $symbols_style = "symbols"
set git_prompt $git_prompt(set_color -o $budspencer_colors[8])" →"
else
set git_prompt $git_prompt(set_color $budspencer_colors[8])" "$git_status[4]
end
end
if test $git_status[5] -gt 0
if test $symbols_style = "symbols"
set git_prompt $git_prompt(set_color -o $budspencer_colors[9])" ═"
else
set git_prompt $git_prompt(set_color $budspencer_colors[9])" "$git_status[5]
end
end
if test $git_status[6] -gt 0
if test $symbols_style = "symbols"
set git_prompt $git_prompt(set_color -o $budspencer_colors[4])" ●"
else
set git_prompt $git_prompt(set_color $budspencer_colors[4])" "$git_status[6]
end
end
set -l git_stashed (__budspencer_is_git_stashed) set -l git_stashed (__budspencer_is_git_stashed)
if test $git_stashed -gt 0
if test $symbols_style = "symbols"
set git_prompt $git_prompt(set_color -o $budspencer_colors[11])" ✭"
else
set git_prompt $git_prompt(set_color $budspencer_colors[11])" "$git_stashed
end
end
echo -n $git_prompt
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
set_color $budspencer_colors[3]
echo -n ''
set_color -b $budspencer_colors[3]
if [ $symbols_style = 'symbols' ]
if [ (count $git_ahead_behind) -eq 2 ]
if [ $git_ahead_behind[1] -gt 0 ]
set_color -o $budspencer_colors[5]
echo -n ' ↑'
end
if [ $git_ahead_behind[2] -gt 0 ]
set_color -o $budspencer_colors[5]
echo -n ' ↓'
end
end
if [ $git_status[1] -gt 0 ]
set_color -o $budspencer_colors[12]
echo -n ' +'
end
if [ $git_status[2] -gt 0 ]
set_color -o $budspencer_colors[7]
echo -n ' '
end
if [ $git_status[3] -gt 0 ]
set_color -o $budspencer_colors[10]
echo -n ' ✱'
end
if [ $git_status[4] -gt 0 ]
set_color -o $budspencer_colors[8]
echo -n ' →'
end
if [ $git_status[5] -gt 0 ]
set_color -o $budspencer_colors[9]
echo -n ' ═'
end
if [ $git_status[6] -gt 0 ]
set_color -o $budspencer_colors[4]
echo -n ' ●'
end
if [ $git_stashed -gt 0 ]
set_color -o $budspencer_colors[11]
echo -n ' ✭'
end
else
if [ (count $git_ahead_behind) -eq 2 ]
if [ $git_ahead_behind[1] -gt 0 ]
set_color $budspencer_colors[5]
echo -n ' '$git_ahead_behind[1]
end
if [ $git_ahead_behind[2] -gt 0 ]
set_color $budspencer_colors[5]
echo -n ' '$git_ahead_behind[2]
end
end
if [ $git_status[1] -gt 0 ]
set_color $budspencer_colors[12]
echo -n ' '$git_status[1]
end
if [ $git_status[2] -gt 0 ]
set_color $budspencer_colors[7]
echo -n ' '$git_status[2]
end
if [ $git_status[3] -gt 0 ]
set_color $budspencer_colors[10]
echo -n ' '$git_status[3]
end
if [ $git_status[4] -gt 0 ]
set_color $budspencer_colors[8]
echo -n ' '$git_status[4]
end
if [ $git_status[5] -gt 0 ]
set_color $budspencer_colors[9]
echo -n ' '$git_status[5]
end
if [ $git_status[6] -gt 0 ]
set_color $budspencer_colors[4]
echo -n ' '$git_status[6]
end
if [ $git_stashed -gt 0 ]
set_color $budspencer_colors[11]
echo -n ' '$git_stashed
end
end
set_color -b $budspencer_colors[3] normal
end 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 test (count $SSH_CLIENT) -gt 0 if set -q SSH_CLIENT
if test $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
switch $fish_bind_mode set_color $budspencer_current_bindmode_color
case default echo -n ''
set_color $budspencer_colors[10]
echo -n ""
set_color normal set_color normal
set_color -b $budspencer_colors[10] $budspencer_colors[1] set_color -b $budspencer_current_bindmode_color $budspencer_colors[1]
case insert if [ (count $budspencer_prompt_error) != 1 ]
set_color $budspencer_colors[5]
echo -n ""
set_color normal
set_color -b $budspencer_colors[5] $budspencer_colors[1]
case visual
set_color $budspencer_colors[8]
echo -n ""
set_color normal
set_color -b $budspencer_colors[8] $budspencer_colors[1]
end
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
echo -n " $budspencer_prompt_error "
set -e budspencer_prompt_error[1]
end
set_color normal set_color normal
end end
@ -232,26 +232,7 @@ end
# => Prompt # => Prompt
############################################################################### ###############################################################################
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)
#############
# => Segments
#############
# Command duration
set ps_duration (fish_cmd_duration_cm)
# Git
set ps_git (__budspencer_prompt_git_symbols)
if test -n "$ps_git"
set ps_git (set_color $budspencer_colors[3])""(set_color -b $budspencer_colors[3])""$ps_git(set_color -b $budspencer_colors[3] normal)
end
# Pwd
set -l ps_pwd ""
set ps_pwd (__budspencer_prompt_pwd)
# Right prompt
echo -n $ps_duration $ps_git $ps_pwd
set_color normal set_color normal
end end