Avoid calling echo to expand fzf args

ZSH_FZF_HISTORY_SEARCH_FZF_ARGS and
ZSH_FZF_HISTORY_SEARCH_FZF_EXTRA_ARGS may contain multiple arguments
separated by spaces that need to be expanded to build the command line
for fzf.  This is currently done by calling a subshell and letting
echo handle it.

Unlike other shells, zsh does not do word splitting by default.
According to zshexpn(1) you can perform word splitting using the rules
for SH_WORD_SPLIT by using the ${=spec} construct.  Avoid creating a
subshell and just expand the spaces.
This commit is contained in:
Javi Merino
2022-05-09 07:03:59 +01:00
parent 399e96606a
commit 5abc3e2204

View File

@@ -19,7 +19,7 @@ typeset -g ZSH_FZF_HISTORY_SEARCH_END_OF_LINE=''
fzf_history_search() {
setopt extendedglob
candidates=(${(f)"$(fc -li -1 0 | fzf $(echo $ZSH_FZF_HISTORY_SEARCH_FZF_ARGS) $(echo $ZSH_FZF_HISTORY_SEARCH_FZF_EXTRA_ARGS) -q "$BUFFER")"})
candidates=(${(f)"$(fc -li -1 0 | fzf ${=ZSH_FZF_HISTORY_SEARCH_FZF_ARGS} ${=ZSH_FZF_HISTORY_SEARCH_FZF_EXTRA_ARGS} -q "$BUFFER")"})
local ret=$?
if [ -n "$candidates" ]; then
BUFFER="${candidates[@]/(#m)*/${${(As: :)MATCH}[4,-1]}}"