summaryrefslogtreecommitdiff
path: root/shell/key-bindings.fish
diff options
context:
space:
mode:
authorbitraid <bitraid@protonmail.ch>2024-11-13 10:40:33 +0200
committerJunegunn Choi <junegunn.c@gmail.com>2024-11-18 19:08:34 +0900
commit99f1bc01773499754e79bce0776330075fdb7a64 (patch)
tree1b7a2cbd25c1cf1ff76c118337aaa4bd70224dcf /shell/key-bindings.fish
parented76f076ddb81d0350b7c00bab279a6520bf6f09 (diff)
downloadfzf-99f1bc01773499754e79bce0776330075fdb7a64.tar.gz
[fish] Format history using builtins if perl is missing
Diffstat (limited to 'shell/key-bindings.fish')
-rw-r--r--shell/key-bindings.fish14
1 files changed, 8 insertions, 6 deletions
diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish
index c66d0793..1f67c3d0 100644
--- a/shell/key-bindings.fish
+++ b/shell/key-bindings.fish
@@ -71,15 +71,17 @@ function fzf_key_bindings
# history's -z flag was added in fish 2.4.0, so don't use it for versions
# before 2.4.0.
if [ "$FISH_MAJOR" -gt 2 -o \( "$FISH_MAJOR" -eq 2 -a "$FISH_MINOR" -ge 4 \) ];
- if type -P perl > /dev/null 2>&1
- set -lx FZF_DEFAULT_OPTS (__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '"\t"↳ ' --highlight-line $FZF_CTRL_R_OPTS +m")
- set -lx FZF_DEFAULT_OPTS_FILE ''
+ set -lx FZF_DEFAULT_OPTS (__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '"\t"↳ ' --highlight-line $FZF_CTRL_R_OPTS +m")
+ set -lx FZF_DEFAULT_OPTS_FILE ''
+ if type -q perl
builtin history -z --reverse | command perl -0 -pe 's/^/$.\t/g; s/\n/\n\t/gm' | eval (__fzfcmd) --tac --read0 --print0 -q '(commandline)' | string replace -r '^\d*\t' '' | read -lz result
and commandline -- $result
else
- set -lx FZF_DEFAULT_OPTS (__fzf_defaults "" "--scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '"\t"↳ ' --highlight-line $FZF_CTRL_R_OPTS +m")
- set -lx FZF_DEFAULT_OPTS_FILE ''
- builtin history -z | eval (__fzfcmd) --read0 --print0 -q '(commandline)' | read -lz result
+ set -l line 0
+ for i in (builtin history -z --reverse | string split0)
+ set line (math $line + 1)
+ string escape -n -- $line\t$i
+ end | string join0 | string replace -a '\n' '\n\t' | string unescape -n | eval (__fzfcmd) --tac --read0 --print0 -q '(commandline)' | string replace -r '^\d*\t' '' | read -lz result
and commandline -- $result
end
else