[fish] Make widgets work with --option= prefix (#2383)

Co-authored-by: Junegunn Choi <junegunn.c@gmail.com>
This commit is contained in:
Jannik Vieten 2021-03-08 14:59:56 +01:00 committed by GitHub
parent cbfbb49ab4
commit f4e1ed25f2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -20,6 +20,7 @@ function fzf_key_bindings
set -l commandline (__fzf_parse_commandline) set -l commandline (__fzf_parse_commandline)
set -l dir $commandline[1] set -l dir $commandline[1]
set -l fzf_query $commandline[2] set -l fzf_query $commandline[2]
set -l prefix $commandline[3]
# "-path \$dir'*/\\.*'" matches hidden files/folders inside $dir but not # "-path \$dir'*/\\.*'" matches hidden files/folders inside $dir but not
# $dir itself, even if hidden. # $dir itself, even if hidden.
@ -42,6 +43,7 @@ function fzf_key_bindings
commandline -t "" commandline -t ""
end end
for i in $result for i in $result
commandline -it -- $prefix
commandline -it -- (string escape $i) commandline -it -- (string escape $i)
commandline -it -- ' ' commandline -it -- ' '
end end
@ -74,6 +76,7 @@ function fzf_key_bindings
set -l commandline (__fzf_parse_commandline) set -l commandline (__fzf_parse_commandline)
set -l dir $commandline[1] set -l dir $commandline[1]
set -l fzf_query $commandline[2] set -l fzf_query $commandline[2]
set -l prefix $commandline[3]
test -n "$FZF_ALT_C_COMMAND"; or set -l FZF_ALT_C_COMMAND " test -n "$FZF_ALT_C_COMMAND"; or set -l FZF_ALT_C_COMMAND "
command find -L \$dir -mindepth 1 \\( -path \$dir'*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \ command find -L \$dir -mindepth 1 \\( -path \$dir'*/\\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \
@ -88,6 +91,7 @@ function fzf_key_bindings
# Remove last token from commandline. # Remove last token from commandline.
commandline -t "" commandline -t ""
commandline -it -- $prefix
end end
end end
@ -116,9 +120,15 @@ function fzf_key_bindings
bind -M insert \ec fzf-cd-widget bind -M insert \ec fzf-cd-widget
end end
function __fzf_parse_commandline -d 'Parse the current command line token and return split of existing filepath and rest of token' function __fzf_parse_commandline -d 'Parse the current command line token and return split of existing filepath, fzf query, and optional -option= prefix'
set -l commandline (commandline -t)
# strip -option= from token if present
set -l prefix (string match -r -- '^-[^\s=]+=' $commandline)
set commandline (string replace -- "$prefix" '' $commandline)
# eval is used to do shell expansion on paths # eval is used to do shell expansion on paths
set -l commandline (eval "printf '%s' "(commandline -t)) eval set commandline $commandline
if [ -z $commandline ] if [ -z $commandline ]
# Default to current directory with no --query # Default to current directory with no --query
@ -138,6 +148,7 @@ function fzf_key_bindings
echo $dir echo $dir
echo $fzf_query echo $fzf_query
echo $prefix
end end
function __fzf_get_dir -d 'Find the longest existing filepath from input string' function __fzf_get_dir -d 'Find the longest existing filepath from input string'