From d282a1649d7d953f028306f13d6616958f3fd1f3 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Wed, 13 Mar 2024 20:56:31 +0900 Subject: Add walker options and replace 'find' with the built-in walker (#3649) --- shell/completion.zsh | 46 ++++++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 20 deletions(-) (limited to 'shell/completion.zsh') diff --git a/shell/completion.zsh b/shell/completion.zsh index c4ba2c75..163b0299 100644 --- a/shell/completion.zsh +++ b/shell/completion.zsh @@ -77,22 +77,19 @@ fi { # To use custom commands instead of find, override _fzf_compgen_{path,dir} -if ! declare -f _fzf_compgen_path > /dev/null; then - _fzf_compgen_path() { - echo "$1" - command find -L "$1" \ - -name .git -prune -o -name .hg -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \ - -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@' - } -fi - -if ! declare -f _fzf_compgen_dir > /dev/null; then - _fzf_compgen_dir() { - command find -L "$1" \ - -name .git -prune -o -name .hg -prune -o -name .svn -prune -o -type d \ - -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@' - } -fi +# +# _fzf_compgen_path() { +# echo "$1" +# command find -L "$1" \ +# -name .git -prune -o -name .hg -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \ +# -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@' +# } +# +# _fzf_compgen_dir() { +# command find -L "$1" \ +# -name .git -prune -o -name .hg -prune -o -name .svn -prune -o -type d \ +# -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@' +# } ########################################################### @@ -148,10 +145,19 @@ __fzf_generic_path_completion() { leftover=${leftover/#\/} [ -z "$dir" ] && dir='.' [ "$dir" != "/" ] && dir="${dir/%\//}" - matches=$(eval "$compgen $(printf %q "$dir")" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --scheme=path --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_COMPLETION_OPTS-}" __fzf_comprun "$cmd" ${(Q)${(Z+n+)fzf_opts}} -q "$leftover" | while read item; do - item="${item%$suffix}$suffix" - echo -n "${(q)item} " - done) + matches=$( + unset FZF_DEFAULT_COMMAND + export FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --scheme=path --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_COMPLETION_OPTS-}" + if declare -f "$compgen" > /dev/null; then + eval "$compgen $(printf %q "$dir")" | __fzf_comprun "$cmd" ${(Q)${(Z+n+)fzf_opts}} -q "$leftover" + else + [[ $compgen =~ dir ]] && walker=dir,follow || walker=file,dir,follow,hidden + __fzf_comprun "$cmd" ${(Q)${(Z+n+)fzf_opts}} -q "$leftover" --walker "$walker" --walker-root="$dir" < /dev/tty + fi | while read item; do + item="${item%$suffix}$suffix" + echo -n "${(q)item} " + done + ) matches=${matches% } if [ -n "$matches" ]; then LBUFFER="$lbuf$matches$tail" -- cgit v1.2.3