From 573e175d5e60cf4c8748cec4cbeca0adc57b7df4 Mon Sep 17 00:00:00 2001 From: bitraid Date: Thu, 19 Dec 2024 10:31:52 +0200 Subject: [PATCH 1/3] [fish] Don't strip leading dot (.) character Fix the removal of the leading dot character from the query, when was pressed and the current command line token started with a dot. It was also removed when was pressed and the directory didn't exist under the current path. --- shell/key-bindings.fish | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish index 745a89f1baf..06955b699bf 100644 --- a/shell/key-bindings.fish +++ b/shell/key-bindings.fish @@ -172,7 +172,7 @@ function fzf_key_bindings # BUG: on combined expressions, if a left argument is a single `!`, the # builtin test command of fish will treat it as the ! operator. To # overcome this, have the variable parts on the right. - if test "." = "$dir" -a "." != (string sub -l 1 -- $commandline) + if test "." = "$dir" -a "./" != (string sub -l 2 -- $commandline) # if $dir is "." but commandline is not a relative path, this means no file path found set fzf_query $commandline else From 1b9f5f45b4c50f313a643467cb368f16cb78cffa Mon Sep 17 00:00:00 2001 From: bitraid Date: Thu, 19 Dec 2024 11:14:54 +0200 Subject: [PATCH 2/3] [fish] Enable home dir expansion of leading ~/ Enable expanding to user's home directory, when pressing or , and the current command line token starts with `~/`. --- shell/key-bindings.fish | 3 +++ 1 file changed, 3 insertions(+) diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish index 06955b699bf..9a0dcc31c09 100644 --- a/shell/key-bindings.fish +++ b/shell/key-bindings.fish @@ -150,6 +150,9 @@ function fzf_key_bindings 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. From 85fde69757c596ed420d35a93bdad5f7f4c382b2 Mon Sep 17 00:00:00 2001 From: bitraid Date: Thu, 19 Dec 2024 11:36:37 +0200 Subject: [PATCH 3/3] [fish] Small syntax modification of some commands No actual change, just for consistency with the rest of the code. --- shell/key-bindings.fish | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish index 9a0dcc31c09..b1c3689600d 100644 --- a/shell/key-bindings.fish +++ b/shell/key-bindings.fish @@ -57,8 +57,8 @@ function fzf_key_bindings function fzf-history-widget -d "Show command history" test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40% begin - set -l FISH_MAJOR (string split '.' -- $version)[1] - set -l FISH_MINOR (string split '.' -- $version)[2] + set -l FISH_MAJOR (string split -f 1 -- '.' $version) + set -l FISH_MINOR (string split -f 2 -- '.' $version) # merge history from other sessions before searching test -z "$fish_private_mode"; and builtin history merge @@ -157,13 +157,13 @@ function fzf_key_bindings # so that after eval, the original string is returned, but with the # variable names replaced by their values. set commandline (string escape -n -- $commandline) - set commandline (string replace -r -a '\x5c\$(?=[\w])' '\$' -- $commandline) + set commandline (string replace -r -a -- '\x5c\$(?=[\w])' '\$' $commandline) # eval is used to do shell expansion on paths eval set commandline $commandline # Combine multiple consecutive slashes into one - set commandline (string replace -r -a '/+' '/' -- $commandline) + set commandline (string replace -r -a -- '/+' '/' $commandline) if test -z "$commandline" # Default to current directory with no --query @@ -180,7 +180,7 @@ function fzf_key_bindings set fzf_query $commandline else # Also remove trailing slash after dir, to "split" input properly - set fzf_query (string replace -r "^$dir/?" '' -- $commandline) + set fzf_query (string replace -r -- "^$dir/?" '' $commandline) end end @@ -193,7 +193,7 @@ function fzf_key_bindings set dir $argv # Strip trailing slash, unless $dir is root dir (/) - set dir (string replace -r '(?