diff options
| author | bitraid <bitraid@protonmail.ch> | 2025-04-16 20:56:33 +0300 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2025-04-28 00:27:51 +0900 |
| commit | ad33165fa78062b4886ae950f4bff2bcb7333923 (patch) | |
| tree | b3739071bad2fafa548ca7fa0cd3b62c811dd295 | |
| parent | 2055db61c8026648fc36873468a7453d2adfcfdf (diff) | |
| download | fzf-ad33165fa78062b4886ae950f4bff2bcb7333923.tar.gz | |
[fish] History: Operate only on line at cursor
This allows inserting history entries when constructing multiline
commands.
| -rw-r--r-- | shell/key-bindings.fish | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish index 0004c380..4760e2e0 100644 --- a/shell/key-bindings.fish +++ b/shell/key-bindings.fish @@ -147,7 +147,10 @@ function fzf_key_bindings end function fzf-history-widget -d "Show command history" - set -l fzf_query (commandline | string escape) + set -l -- command_line (commandline) + set -l -- current_line (commandline -L) + set -l -- total_lines (count $command_line) + set -l -- fzf_query (string escape -- $command_line[$current_line]) set -lx FZF_DEFAULT_OPTS (__fzf_defaults '' \ '--nth=2..,.. --scheme=history --multi --wrap-sign="\t↳ "' \ @@ -172,9 +175,13 @@ function fzf_key_bindings test -z "$fish_private_mode"; and builtin history merge if set -l result (eval $FZF_DEFAULT_COMMAND \| (__fzfcmd) --query=$fzf_query | string split0) - commandline -- (string replace -a -- \n\t \n $result[1]) - test (count $result) -gt 1; and for i in $result[2..-1] - commandline -i -- (string replace -a -- \n\t \n \n$i) + if test "$total_lines" -eq 1 + commandline -- (string replace -a -- \n\t \n $result) + else + set -l a (math $current_line - 1) + set -l b (math $current_line + 1) + commandline -- $command_line[1..$a] (string replace -a -- \n\t \n $result) + commandline -a -- '' $command_line[$b..-1] end end |
