diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish index fe61280d..2c8c8df6 100644 --- a/shell/key-bindings.fish +++ b/shell/key-bindings.fish @@ -136,39 +136,41 @@ function fzf_key_bindings end 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) + set -l dir '.' + set -l query + set -l commandline (commandline -t | string unescape -n) - # strip -option= from token if present + # Strip -option= from token if present set -l prefix (string match -r -- '^-[^\s=]+=' $commandline) set commandline (string replace -- "$prefix" '' $commandline) # Enable home directory expansion of leading ~/ set commandline (string replace -r -- '^~/' '\$HOME/' $commandline) - # escape special characters, except for the $ sign of valid variable names, - # so that after eval, the original string is returned, but with the - # variable names replaced by their values. + # Escape special characters, except for the $ sign of valid variable names, + # so that the original string with expanded variables is returned after eval. set commandline (string escape -n -- $commandline) - set commandline (string replace -r -a -- '\x5c\$(?=[\w])' '\$' $commandline) + set commandline (string replace -r -a -- '\\\\\$(?=[\w])' '\$' $commandline) # eval is used to do shell expansion on paths eval set commandline $commandline - # Combine multiple consecutive slashes into one, and unescape. - set commandline (string replace -r -a -- '/+' '/' $commandline | string unescape -n) + # Combine multiple consecutive slashes into one. + set commandline (string replace -r -a -- '/+' '/' $commandline) - if test -z "$commandline" - # Default to current directory with no --query - set dir '.' - set fzf_query '' - else - set dir (__fzf_get_dir $commandline) + if test -n "$commandline" + # Strip trailing slash, unless $dir is root dir (/) + set dir (string replace -r -- '(?