junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
65.81k stars 2.41k forks source link

why cd ../**<TAB> not work? #4048

Closed qizhengyang2017 closed 1 month ago

qizhengyang2017 commented 1 month ago

Checklist

Output of fzf --version

0.55.0 (brew)/ 0.55.0 (fc69308)

OS

Shell

Problem / Steps to reproduce

When using vim ../**<TAB>, I can match files in the parent directory, but when using cd ../**<TAB>, I can’t match the folders. Why is that?

LangLangBart commented 1 month ago

vim ../**

vim works because it runs with:

FZF_DEFAULT_COMMAND= fzf --walker file,dir,follow,hidden --walker-root=..

cd runs with:

FZF_DEFAULT_COMMAND= fzf --walker dir,follow --walker-root=..

This appears to be correct, but if the hidden option is not enabled, it skips directories starting with a . (dot), including ...

https://github.com/junegunn/fzf/blob/3c40b1bd51a895a907dbae5d30f6d9e99bdc1f90/src/reader.go#L267-L270

A potential fix could be:

--- a/src/reader.go
+++ b/src/reader.go
@@ -266,5 +266,5 @@ func (r *Reader) readFiles(root string, opts walkerOpts, ignores []string) bool
      if isDir || opts.follow && isSymlinkToDir(path, de) {
        base := filepath.Base(path)
-       if !opts.hidden && base[0] == '.' {
+       if !opts.hidden && base != ".." && base[0] == '.' {
          return filepath.SkipDir
        }

Alternatively, you can use this workaround:

export FZF_COMPLETION_DIR_OPTS='--walker dir,follow,hidden'

https://github.com/junegunn/fzf/blob/3c40b1bd51a895a907dbae5d30f6d9e99bdc1f90/shell/completion.zsh#L166-L173

If too many hidden folders are displayed, use the --walker-skip=DIRS flag. Default values are explained in the CHANGELOG[^1] and fzf's man page.

[^1]: fzf/CHANGELOG.md · 0.48.0

junegunn commented 1 month ago

Thanks @LangLangBart, patch pushed to master.