Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add --builtin-filter-dirs #3464

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/core.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ func Run(opts *Options, version string, revision string) {
reader = NewReader(func(data []byte) bool {
return chunkList.Push(data)
}, eventBox, opts.ReadZero, opts.Filter == nil)
go reader.ReadSource()
go reader.ReadSource(opts.FilterDirs)
}

// Matcher
Expand Down Expand Up @@ -165,7 +165,7 @@ func Run(opts *Options, version string, revision string) {
}
return false
}, eventBox, opts.ReadZero, false)
reader.ReadSource()
reader.ReadSource(opts.FilterDirs)
} else {
eventBox.Unwatch(EvtReadNew)
eventBox.WaitFor(EvtReadFin)
Expand Down
6 changes: 6 additions & 0 deletions src/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ const usage = `usage: fzf [options]
--tiebreak=CRI[,..] Comma-separated list of sort criteria to apply
when the scores are tied [length|chunk|begin|end|index]
(default: length)
--builtin-filter-dirs Filter directories instead of files when FZF_DEFAULT_COMMAND
is not set and input is not tty

Interface
-m, --multi[=MAX] Enable multi-select with tab/shift-tab
Expand Down Expand Up @@ -336,6 +338,7 @@ type Options struct {
Tabstop int
ListenPort *int
ClearOnExit bool
FilterDirs bool
Version bool
}

Expand Down Expand Up @@ -405,6 +408,7 @@ func defaultOptions() *Options {
BorderLabel: labelOpts{},
PreviewLabel: labelOpts{},
ClearOnExit: true,
FilterDirs: false,
Version: false}
}

Expand Down Expand Up @@ -1821,6 +1825,8 @@ func parseOptions(opts *Options, allArgs []string) {
opts.ClearOnExit = true
case "--no-clear":
opts.ClearOnExit = false
case "--builtin-filter-dirs":
opts.FilterDirs = true
case "--version":
opts.Version = true
case "--":
Expand Down
8 changes: 4 additions & 4 deletions src/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func (r *Reader) restart(command string) {
}

// ReadSource reads data from the default command or from standard input
func (r *Reader) ReadSource() {
func (r *Reader) ReadSource(readDirs bool) {
r.startEventPoller()
var success bool
if util.IsTty() {
Expand All @@ -115,7 +115,7 @@ func (r *Reader) ReadSource() {
if defaultCommand != "" {
success = r.readFromCommand(&shell, defaultCommand)
} else {
success = r.readFiles()
success = r.readFilesOrDirs(readDirs)
}
} else {
success = r.readFromCommand(nil, cmd)
Expand Down Expand Up @@ -161,7 +161,7 @@ func (r *Reader) readFromStdin() bool {
return true
}

func (r *Reader) readFiles() bool {
func (r *Reader) readFilesOrDirs(readDirs bool) bool {
r.killed = false
fn := func(path string, mode os.FileInfo) error {
path = filepath.Clean(path)
Expand All @@ -170,7 +170,7 @@ func (r *Reader) readFiles() bool {
if isDir && filepath.Base(path)[0] == '.' {
return filepath.SkipDir
}
if !isDir && r.pusher([]byte(path)) {
if ((isDir && readDirs) || (!isDir && !readDirs)) && r.pusher([]byte(path)) {
atomic.StoreInt32(&r.event, int32(EvtReadNew))
}
}
Expand Down