diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2024-11-26 17:26:16 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2024-11-26 17:26:16 +0900 |
| commit | 7d9548919e9b1bb05bb95225275e34213a747cde (patch) | |
| tree | 93ad865dbddfa8329f8ce51a4b1d930a0d9f0411 /src/reader.go | |
| parent | bee80a730f945c05ac0167130b9204206371d570 (diff) | |
| download | fzf-7d9548919e9b1bb05bb95225275e34213a747cde.tar.gz | |
Extend --walker-skip to support multi-component patterns
fzf --walker-skip 'foo/bar'
Close #4107
Diffstat (limited to 'src/reader.go')
| -rw-r--r-- | src/reader.go | 33 |
1 files changed, 32 insertions, 1 deletions
diff --git a/src/reader.go b/src/reader.go index 80387bac..d78f10ff 100644 --- a/src/reader.go +++ b/src/reader.go @@ -7,6 +7,7 @@ import ( "io/fs" "os" "path/filepath" + "strings" "sync" "sync/atomic" "time" @@ -272,6 +273,26 @@ func (r *Reader) readFiles(roots []string, opts walkerOpts, ignores []string) bo ToSlash: fastwalk.DefaultToSlash(), Sort: fastwalk.SortFilesFirst, } + ignoresBase := []string{} + ignoresFull := []string{} + ignoresSuffix := []string{} + sep := string(os.PathSeparator) + for _, ignore := range ignores { + if strings.ContainsRune(ignore, os.PathSeparator) { + if strings.HasPrefix(ignore, sep) { + ignoresSuffix = append(ignoresSuffix, ignore) + } else { + // 'foo/bar' should match match + // * 'foo/bar' + // * 'baz/foo/bar' + // * but NOT 'bazfoo/bar' + ignoresFull = append(ignoresFull, ignore) + ignoresSuffix = append(ignoresSuffix, sep+ignore) + } + } else { + ignoresBase = append(ignoresBase, ignore) + } + } fn := func(path string, de os.DirEntry, err error) error { if err != nil { return nil @@ -284,11 +305,21 @@ func (r *Reader) readFiles(roots []string, opts walkerOpts, ignores []string) bo if !opts.hidden && base[0] == '.' && base != ".." { return filepath.SkipDir } - for _, ignore := range ignores { + for _, ignore := range ignoresBase { if ignore == base { return filepath.SkipDir } } + for _, ignore := range ignoresFull { + if ignore == path { + return filepath.SkipDir + } + } + for _, ignore := range ignoresSuffix { + if strings.HasSuffix(path, ignore) { + return filepath.SkipDir + } + } } if ((opts.file && !isDir) || (opts.dir && isDir)) && r.pusher(stringBytes(path)) { atomic.StoreInt32(&r.event, int32(EvtReadNew)) |
