diff --git a/files/fish/fish_abbreviations b/files/fish/abbreviations.fish similarity index 100% rename from files/fish/fish_abbreviations rename to files/fish/abbreviations.fish diff --git a/files/fish/fish_key_bindings b/files/fish/fish_key_bindings deleted file mode 100644 index f935421..0000000 --- a/files/fish/fish_key_bindings +++ /dev/null @@ -1,144 +0,0 @@ -set -l init_mode insert - -if contains -- $argv[1] insert default visual - set init_mode $argv[1] -else if set -q argv[1] - # We should still go on so the bindings still get set. - echo "Unknown argument $argv" >&2 -end - -# Inherit shared key bindings. -# Do this first so vi-bindings win over default. -for mode in insert default visual - __fish_shared_key_bindings -s -M $mode -end - -# Add a way to switch from insert to normal (command) mode. -# Note if we are paging, we want to stay in insert mode -# See #2871 -bind -s --preset -M insert \e "if commandline -P; commandline -f cancel; else; set fish_bind_mode default; commandline -f backward-char repaint-mode; end" - -# Default (command) mode -bind -s --preset :q exit -bind -s --preset -m insert \cc cancel-commandline repaint-mode -bind -s --preset -M default h backward-char -bind -s --preset -M default l forward-char -bind -s --preset -M visual h begin-selection backward-char -bind -s --preset -M visual l begin-selection forward-char -bind -s --preset -m insert \n execute -bind -s --preset -m insert \r execute -bind -s --preset -m insert o insert-line-under repaint-mode -bind -s --preset -m insert O insert-line-over repaint-mode -bind -s --preset -m insert i repaint-mode -bind -s --preset -m insert I beginning-of-line repaint-mode -bind -s --preset -m insert a forward-single-char repaint-mode -bind -s --preset -m insert A end-of-line repaint-mode - -# Selection keys (if in default mode) -bind -s --preset -M default -m visual H begin-selection backward-char -bind -s --preset -M default -m visual L begin-selection forward-char -bind -s --preset -M default -m visual J begin-selection down-or-search -bind -s --preset -M default -m visual K begin-selection up-or-search -bind -s --preset -M default -m visual x beginning-of-line begin-selection end-of-line -# TODO: Implement x when already in visual mode -# (if already in visual mode) -bind -s --preset -M visual H backward-char -bind -s --preset -M visual L forward-char -bind -s --preset -M visual J backward-char -bind -s --preset -M visual K backward-char - -# Goto keys -bind -s --preset gh end-selection beginning-of-line -bind -s --preset gj end-selection end-of-buffer -bind -s --preset gk end-selection beginning-of-buffer -bind -s --preset gl end-selection end-of-line -bind -s --preset gg end-selection beginning-of-buffer - -# (Goto+Selection) keys -bind -s --preset -M default -m visual gH begin-selection beginning-of-line -bind -s --preset -M default -m visual gJ begin-selection end-of-buffer -bind -s --preset -M default -m visual gK begin-selection beginning-of-buffer -bind -s --preset -M default -m visual gL begin-selection end-of-line -bind -s --preset -M visual gH beginning-of-line -bind -s --preset -M visual gJ end-of-buffer -bind -s --preset -M visual gK beginning-of-buffer -bind -s --preset -M visual gL end-of-line - -# Undo keys -bind -s --preset u undo -bind -s --preset U redo - -# History navigation -bind -s --preset / history-pager --sets-mode insert repaint - -bind -s --preset k up-or-search -bind -s --preset j down-or-search -bind -s --preset b -m visual backward-word -bind -s --preset B -m visual backward-bigword -bind -s --preset w -m visual forward-word forward-single-char -bind -s --preset W -m visual forward-bigword forward-single-char - -# Backspace deletes a char in insert mode -bind -s --preset -M insert -k backspace backward-delete-char -bind -s --preset -M insert \ch backward-delete-char -bind -s --preset -M insert \x7f backward-delete-char - -bind -s --preset -M visual d kill-selection - -bind -s --preset '~' togglecase-char forward-single-char -bind -s --preset gu downcase-word -bind -s --preset gU upcase-word - -bind -s --preset J end-of-line delete-char -bind -s --preset K 'man (commandline -t) 2>/dev/null; or echo -n \a' - -bind -s --preset y yank-selection - -bind -s --preset -m normal -M visual f forward-jump -bind -s --preset -m normal -M visual t forward-jump-till -bind -s --preset -m normal -M visual F backward-jump -bind -s --preset -m normal -M visual T backward-jump-till - -bind -s --preset p forward-char yank -bind -s --preset P yank -bind -s --preset gp yank-pop - -# same vim 'pasting' note as upper -bind -s --preset '"*p' forward-char "commandline -i ( xsel -p; echo )[1]" -bind -s --preset '"*P' "commandline -i ( xsel -p; echo )[1]" - -# -# Lowercase r, enters replace_one mode -# -bind -s --preset -m replace_one r repaint-mode -bind -s --preset -M replace_one -m default '' delete-char self-insert backward-char repaint-mode -bind -s --preset -M replace_one -m default \r 'commandline -f delete-char; commandline -i \n; commandline -f backward-char; commandline -f repaint-mode' -bind -s --preset -M replace_one -m default \e cancel repaint-mode - -# -# Uppercase R, enters replace mode -# -bind -s --preset -m replace R repaint-mode -bind -s --preset -M replace '' delete-char self-insert -bind -s --preset -M replace -m insert \r execute repaint-mode -bind -s --preset -M replace -m default \e cancel repaint-mode - -bind -s --preset -M visual -m insert c kill-selection end-selection repaint-mode -bind -s --preset -M visual -m default '~' togglecase-selection end-selection repaint-mode - -bind -s --preset -M visual -m default \cc end-selection repaint-mode -bind -s --preset -M visual -m default \e end-selection repaint-mode - -# Make it easy to turn an unexecuted command into a comment in the shell history. Also, remove -# the commenting chars so the command can be further edited then executed. -bind -s --preset -M default \# __fish_toggle_comment_commandline -bind -s --preset -M visual \# __fish_toggle_comment_commandline -bind -s --preset -M replace \# __fish_toggle_comment_commandline - -# Set the cursor shape -# After executing once, this will have defined functions listening for the variable. -# Therefore it needs to be before setting fish_bind_mode. -set -g fish_vi_cursor inclusive -set -g fish_cursor_selection_mode inclusive - -set fish_bind_mode $init_mode diff --git a/files/fish/functions/fish_greeting.fish b/files/fish/functions/fish_greeting.fish deleted file mode 120000 index fdad069..0000000 --- a/files/fish/functions/fish_greeting.fish +++ /dev/null @@ -1 +0,0 @@ -/gnu/store/r17n4grhqa12hfvgjkrqyddy7ksavj9a-fish_greeting.fish \ No newline at end of file diff --git a/files/fish/functions/fish_prompt.fish b/files/fish/functions/fish_prompt.fish deleted file mode 120000 index ef02e01..0000000 --- a/files/fish/functions/fish_prompt.fish +++ /dev/null @@ -1 +0,0 @@ -/gnu/store/8mh31d3qyd2gnkqa6zgnnaiyskrk96dm-fish_prompt.fish \ No newline at end of file diff --git a/files/fish/functions/greeting.fish b/files/fish/functions/greeting.fish new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/files/fish/functions/greeting.fish @@ -0,0 +1 @@ + diff --git a/files/fish/functions/prompt.fish b/files/fish/functions/prompt.fish new file mode 100644 index 0000000..93a37b9 --- /dev/null +++ b/files/fish/functions/prompt.fish @@ -0,0 +1,71 @@ +# Utilities + +function blue + set_color blue; printf $argv; set_color normal +end +function normal + set_color normal; printf $argv; set_color normal +end + +function displayed_string_length + string replace -ra -- '\x1b.*?[mGKH]' '' "$argv" | string length +end + +function padding + printf "%-"$argv[1]"s%s" " " "$output" +end + +# Current working directory prompt +function fish_cwd_prompt + set -l cwd (pwd) + switch "$cwd" + case "$HOME" + printf "~" + case "/" + printf "/" + case "*" + set -l parent_dir (basename (dirname $cwd)) + test $parent_dir = "/" || printf "%s" $parent_dir + printf '/%s' (basename $cwd) + end +end + +# Guix environment prompt +function fish_environment_prompt + normal "(env "; blue "%s" (basename $GUIX_ENVIRONMENT); normal ")" +end + +# Actual prompt +function fish_prompt + if test -n "$GUIX_ENVIRONMENT" + set -l fish_environment_prompt_length \ + (displayed_string_length (fish_environment_prompt)) + set -l fish_git_prompt_length \ + (displayed_string_length (fish_git_prompt)) + + fish_environment_prompt + printf (padding (math $COLUMNS - $fish_environment_prompt_length \ + - $fish_git_prompt_length)) + fish_git_prompt | string replace -ra ' ' '' + printf '\n' + else + function fish_right_prompt + fish_git_prompt + end + end + + set -g fish_key_bindings fish_vi_key_bindings + switch "$fish_key_bindings" + case fish_vi_key_bindings fish_hybrid_key_bindings + test $fish_bind_mode = 'default' && normal ':' || normal '+' + end + + blue (whoami); normal ' at '; blue (prompt_hostname) + normal ' in '; blue (fish_cwd_prompt) + normal ' > ' +end + +function fish_default_mode_prompt -d "Display vi prompt mode" + # Do nothing +end + diff --git a/files/fish/fish_variables b/files/fish/variables.fish similarity index 100% rename from files/fish/fish_variables rename to files/fish/variables.fish diff --git a/modules/radix/files/fish.scm b/modules/radix/files/fish.scm index de4c114..f2d8a9d 100644 --- a/modules/radix/files/fish.scm +++ b/modules/radix/files/fish.scm @@ -6,14 +6,13 @@ variables)) (define abbreviations - (local-file "../../../files/fish/fish_abbreviations")) + (local-file "../../../files/fish/abbreviations.fish")) (define functions-greeting - (local-file "../../../files/fish/functions/fish_greeting.fish")) + (local-file "../../../files/fish/functions/greeting.fish")) (define functions-prompt - (local-file "../../../files/fish/functions/fish_prompt.fish")) + (local-file "../../../files/fish/functions/prompt.fish")) (define variables - (local-file "../../../files/fish/fish_variables")) - + (local-file "../../../files/fish/variables.fish"))