summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbitraid <bitraid@protonmail.ch>2024-11-12 19:01:19 +0200
committerJunegunn Choi <junegunn.c@gmail.com>2024-11-18 19:08:34 +0900
commited76f076ddb81d0350b7c00bab279a6520bf6f09 (patch)
treeff31df2976144ad1a479210fcf543585e16c91df
parent4d357d10639017d19fd42cf55bf8b03c7889c890 (diff)
downloadfzf-ed76f076ddb81d0350b7c00bab279a6520bf6f09.tar.gz
[fish] Replace external commands with builtins
- Use `string collect` instead of cat to get the contents of $FZF_DEFAULT_OPTS_FILE. Also, check if the file is readable first. - Use `string split` instead of cut to set $FISH_MAJOR, $FISH_MINOR. - Use `string replace` instead of perl to strip leading tabs.
-rw-r--r--shell/key-bindings.fish8
1 files changed, 4 insertions, 4 deletions
diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish
index f2095783..c66d0793 100644
--- a/shell/key-bindings.fish
+++ b/shell/key-bindings.fish
@@ -23,7 +23,7 @@ function fzf_key_bindings
# $2: Append to FZF_DEFAULT_OPTS_FILE and FZF_DEFAULT_OPTS
test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%
echo "--height $FZF_TMUX_HEIGHT --bind=ctrl-z:ignore" $argv[1]
- command cat "$FZF_DEFAULT_OPTS_FILE" 2> /dev/null
+ test -r "$FZF_DEFAULT_OPTS_FILE"; and string collect -N -- <$FZF_DEFAULT_OPTS_FILE
echo $FZF_DEFAULT_OPTS $argv[2]
end
@@ -59,8 +59,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 (echo $version | cut -f1 -d.)
- set -l FISH_MINOR (echo $version | cut -f2 -d.)
+ set -l FISH_MAJOR (string split '.' -- $version)[1]
+ set -l FISH_MINOR (string split '.' -- $version)[2]
# merge history from other sessions before searching
if test -z "$fish_private_mode"
@@ -74,7 +74,7 @@ function fzf_key_bindings
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 ''
- builtin history -z --reverse | command perl -0 -pe 's/^/$.\t/g; s/\n/\n\t/gm' | eval (__fzfcmd) --tac --read0 --print0 -q '(commandline)' | command perl -pe 's/^\d*\t//' | read -lz result
+ 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")