Skip to content
Myr

[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

1 file+57 added−57 removed

modified:shell/key-bindings.fish+57 added-57 removed
24 unmodified lines
25 (test -r "$FZF_DEFAULT_OPTS_FILE"; and string join -- ' ' <$FZF_DEFAULT_OPTS_FILE) \26 $FZF_DEFAULT_OPTS $argv[2..-1]27 end2829 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 end3940 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)4445 # Strip -option= from token if present46 set -l prefix (string match -r -- '^-[^\s=]+=' $commandline)47 set commandline (string replace -- "$prefix" '' $commandline)4849 # Enable home directory expansion of leading ~/50 set commandline (string replace -r -- '^~/' '\$HOME/' $commandline)5152 # 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)5657 # eval is used to do shell expansion on paths58 eval set commandline $commandline5960 # Combine multiple consecutive slashes into one.61 set commandline (string replace -r -a -- '/+' '/' $commandline)6263 if test -n "$commandline"64 # Strip trailing slash, unless $dir is root dir (/)65 set dir (string replace -r -- '(?<!^)/$' '' $commandline)6667 # 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 end7374 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 end8283 string escape -n -- "$dir" "$fzf_query" "$prefix"84 end8586 # 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 lines
160161 commandline -f repaint162 end163107 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 end117164 bind \cr fzf-history-widget165 bind -M insert \cr fzf-history-widget166167 if not set -q FZF_CTRL_T_COMMAND; or test -n "$FZF_CTRL_T_COMMAND"
5 unmodified lines
173 bind \ec fzf-cd-widget174 bind -M insert \ec fzf-cd-widget175 end176131 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)135136 # Strip -option= from token if present137 set -l prefix (string match -r -- '^-[^\s=]+=' $commandline)138 set commandline (string replace -- "$prefix" '' $commandline)139140 # Enable home directory expansion of leading ~/141 set commandline (string replace -r -- '^~/' '\$HOME/' $commandline)142143 # 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)147148 # eval is used to do shell expansion on paths149 eval set commandline $commandline150151 # Combine multiple consecutive slashes into one.152 set commandline (string replace -r -a -- '/+' '/' $commandline)153154 if test -n "$commandline"155 # Strip trailing slash, unless $dir is root dir (/)156 set dir (string replace -r -- '(?<!^)/$' '' $commandline)157158 # 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 end164165 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 end173174 string escape -n -- "$dir" "$fzf_query" "$prefix"175 end176177end