[fish] Reorder functions
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Move the helper functions to the top of the main function, and the main function commands (bind command) to the bottom.
authored by bitraid · committed by Junegunn Choi · parent 7e9566f · Browse files · 1 file·+57 added−57 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+57 added−57 removed
- other:+57 added−57 removed
Provenance
- Commit
4c9d37d- Tree
0769635- Author
bitraid <bitraid@protonmail.ch>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
7e9566f
1 file changed+57 added−57 removed
modified:shell/key-bindings.fish+57 added-57 removed
24 unmodified lines25 (test -r "$FZF_DEFAULT_OPTS_FILE"; and string join -- ' ' <$FZF_DEFAULT_OPTS_FILE) \26 $FZF_DEFAULT_OPTS $argv[2..-1]27 end28 29+ function __fzfcmd30+ test -n "$FZF_TMUX_HEIGHT"; or set -l FZF_TMUX_HEIGHT 40%31+ if test -n "$FZF_TMUX_OPTS"32+ echo "fzf-tmux $FZF_TMUX_OPTS -- "33+ else if test "$FZF_TMUX" = "1"34+ echo "fzf-tmux -d$FZF_TMUX_HEIGHT -- "35+ else36+ echo "fzf"37+ end38+ end39+40+ function __fzf_parse_commandline -d 'Parse the current command line token and return split of existing filepath, fzf query, and optional -option= prefix'41+ set -l dir '.'42+ set -l query43+ set -l commandline (commandline -t | string unescape -n)44+45+ # Strip -option= from token if present46+ set -l prefix (string match -r -- '^-[^\s=]+=' $commandline)47+ set commandline (string replace -- "$prefix" '' $commandline)48+49+ # Enable home directory expansion of leading ~/50+ set commandline (string replace -r -- '^~/' '\$HOME/' $commandline)51+52+ # Escape special characters, except for the $ sign of valid variable names,53+ # so that the original string with expanded variables is returned after eval.54+ set commandline (string escape -n -- $commandline)55+ set commandline (string replace -r -a -- '\\\\\$(?=[\w])' '\$' $commandline)56+57+ # eval is used to do shell expansion on paths58+ eval set commandline $commandline59+60+ # Combine multiple consecutive slashes into one.61+ set commandline (string replace -r -a -- '/+' '/' $commandline)62+63+ if test -n "$commandline"64+ # Strip trailing slash, unless $dir is root dir (/)65+ set dir (string replace -r -- '(?<!^)/$' '' $commandline)66+67+ # Set $dir to the longest existing filepath68+ while not test -d "$dir"69+ # If path is absolute, this can keep going until ends up at /70+ # If path is relative, this can keep going until entire input is consumed, dirname returns "."71+ set dir (dirname -- $dir)72+ end73+74+ if test "$dir" = '.'; and test (string sub -l 2 -- $commandline) != './'75+ # If $dir is "." but commandline is not a relative path, this means no file path found76+ set fzf_query $commandline77+ else78+ # Also remove trailing slash after dir, to "split" input properly79+ set fzf_query (string replace -r -- "^$dir/?" '' $commandline)80+ end81+ end82+83+ string escape -n -- "$dir" "$fzf_query" "$prefix"84+ end85+86 # Store current token in $dir as root for the 'find' command87 function fzf-file-widget -d "List files and folders"88 set -l commandline (__fzf_parse_commandline)89 set -lx dir $commandline[1]70 unmodified lines160 161 commandline -f repaint162 end163 107- function __fzfcmd108- test -n "$FZF_TMUX_HEIGHT"; or set -l FZF_TMUX_HEIGHT 40%109- if test -n "$FZF_TMUX_OPTS"110- echo "fzf-tmux $FZF_TMUX_OPTS -- "111- else if test "$FZF_TMUX" = "1"112- echo "fzf-tmux -d$FZF_TMUX_HEIGHT -- "113- else114- echo "fzf"115- end116- end117-164 bind \cr fzf-history-widget165 bind -M insert \cr fzf-history-widget166 167 if not set -q FZF_CTRL_T_COMMAND; or test -n "$FZF_CTRL_T_COMMAND"5 unmodified lines173 bind \ec fzf-cd-widget174 bind -M insert \ec fzf-cd-widget175 end176 131- function __fzf_parse_commandline -d 'Parse the current command line token and return split of existing filepath, fzf query, and optional -option= prefix'132- set -l dir '.'133- set -l query134- set -l commandline (commandline -t | string unescape -n)135-136- # Strip -option= from token if present137- set -l prefix (string match -r -- '^-[^\s=]+=' $commandline)138- set commandline (string replace -- "$prefix" '' $commandline)139-140- # Enable home directory expansion of leading ~/141- set commandline (string replace -r -- '^~/' '\$HOME/' $commandline)142-143- # Escape special characters, except for the $ sign of valid variable names,144- # so that the original string with expanded variables is returned after eval.145- set commandline (string escape -n -- $commandline)146- set commandline (string replace -r -a -- '\\\\\$(?=[\w])' '\$' $commandline)147-148- # eval is used to do shell expansion on paths149- eval set commandline $commandline150-151- # Combine multiple consecutive slashes into one.152- set commandline (string replace -r -a -- '/+' '/' $commandline)153-154- if test -n "$commandline"155- # Strip trailing slash, unless $dir is root dir (/)156- set dir (string replace -r -- '(?<!^)/$' '' $commandline)157-158- # Set $dir to the longest existing filepath159- while not test -d "$dir"160- # If path is absolute, this can keep going until ends up at /161- # If path is relative, this can keep going until entire input is consumed, dirname returns "."162- set dir (dirname -- $dir)163- end164-165- if test "$dir" = '.'; and test (string sub -l 2 -- $commandline) != './'166- # If $dir is "." but commandline is not a relative path, this means no file path found167- set fzf_query $commandline168- else169- # Also remove trailing slash after dir, to "split" input properly170- set fzf_query (string replace -r -- "^$dir/?" '' $commandline)171- end172- end173-174- string escape -n -- "$dir" "$fzf_query" "$prefix"175- end176-177 end