Skip to content

Commit 1a50a3c

Browse files
authored
Fix FZF_COMPLETION_{DIR,PATH}_OPTS ignored with custom compgen functions (#4679)
When users define custom _fzf_compgen_path or _fzf_compgen_dir functions, FZF_COMPLETION_PATH_OPTS and FZF_COMPLETION_DIR_OPTS were not applied because the options were only computed inside the walker fallback branch. Close #4592
1 parent fefea8d commit 1a50a3c

File tree

3 files changed

+15
-9
lines changed

3 files changed

+15
-9
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ CHANGELOG
4646
(`SHIFT-DELETE`)
4747
- Added fish completion support (#4605) (@lalvarezt)
4848
- zsh: Handle multi-line history selection (#4595) (@LangLangBart)
49-
- zsh: Fixed `_fzf_compgen_{path,dir}` to respect `FZF_COMPLETION_{PATH,DIR}_OPTS` (#4592) (@LangLangBart)
5049
- Bug fixes
50+
- Fixed `_fzf_compgen_{path,dir}` to respect `FZF_COMPLETION_{PATH,DIR}_OPTS` (#4592) (@shtse8, @LangLangBart)
5151
- Fixed `--preview-window follow` not working correctly with wrapping (#3243, #4258)
5252
- Fixed symlinks to directories being returned as files (#4676) (@skk64)
5353
- Fixed SIGHUP signal handling (#4668) (@LangLangBart)

shell/completion.bash

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,15 +370,18 @@ __fzf_generic_path_completion() {
370370
matches=$(
371371
export FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --scheme=path" "${FZF_COMPLETION_OPTS-} $2")
372372
unset FZF_DEFAULT_COMMAND FZF_DEFAULT_OPTS_FILE
373+
if [[ $1 =~ dir ]]; then
374+
eval "rest=(${FZF_COMPLETION_DIR_OPTS-})"
375+
else
376+
eval "rest=(${FZF_COMPLETION_PATH_OPTS-})"
377+
fi
373378
if declare -F "$1" > /dev/null; then
374-
eval "$1 $(printf %q "$dir")" | __fzf_comprun "$4" -q "$leftover"
379+
eval "$1 $(printf %q "$dir")" | __fzf_comprun "$4" -q "$leftover" "${rest[@]}"
375380
else
376381
if [[ $1 =~ dir ]]; then
377382
walker=dir,follow
378-
eval "rest=(${FZF_COMPLETION_DIR_OPTS-})"
379383
else
380384
walker=file,dir,follow,hidden
381-
eval "rest=(${FZF_COMPLETION_PATH_OPTS-})"
382385
fi
383386
__fzf_comprun "$4" -q "$leftover" --walker "$walker" --walker-root="$dir" "${rest[@]}"
384387
fi | while read -r item; do

shell/completion.zsh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,18 @@ __fzf_generic_path_completion() {
174174
export FZF_DEFAULT_OPTS
175175
FZF_DEFAULT_OPTS=$(__fzf_defaults "--reverse --scheme=path" "${FZF_COMPLETION_OPTS-}")
176176
unset FZF_DEFAULT_COMMAND FZF_DEFAULT_OPTS_FILE
177+
if [[ $compgen =~ dir ]]; then
178+
rest=${FZF_COMPLETION_DIR_OPTS-}
179+
else
180+
rest=${FZF_COMPLETION_PATH_OPTS-}
181+
fi
177182
if declare -f "$compgen" > /dev/null; then
178-
eval "$compgen $(printf %q "$dir")" | __fzf_comprun "$cmd_word" ${(Q)${(Z+n+)fzf_opts}} -q "$leftover"
183+
eval "$compgen $(printf %q "$dir")" | __fzf_comprun "$cmd_word" ${(Q)${(Z+n+)fzf_opts}} -q "$leftover" ${(Q)${(Z+n+)rest}}
179184
else
180185
if [[ $compgen =~ dir ]]; then
181186
walker=dir,follow
182-
rest=${FZF_COMPLETION_DIR_OPTS-}
183187
else
184188
walker=file,dir,follow,hidden
185-
rest=${FZF_COMPLETION_PATH_OPTS-}
186189
fi
187190
__fzf_comprun "$cmd_word" ${(Q)${(Z+n+)fzf_opts}} -q "$leftover" --walker "$walker" --walker-root="$dir" ${(Q)${(Z+n+)rest}} < /dev/tty
188191
fi | while read -r item; do
@@ -204,12 +207,12 @@ __fzf_generic_path_completion() {
204207

205208
_fzf_path_completion() {
206209
__fzf_generic_path_completion "$1" "$2" _fzf_compgen_path \
207-
"${FZF_COMPLETION_PATH_OPTS-} -m" "" " "
210+
"-m" "" " "
208211
}
209212

210213
_fzf_dir_completion() {
211214
__fzf_generic_path_completion "$1" "$2" _fzf_compgen_dir \
212-
"${FZF_COMPLETION_DIR_OPTS-}" "/" ""
215+
"" "/" ""
213216
}
214217

215218
_fzf_feed_fifo() {

0 commit comments

Comments
 (0)