summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/constants.go2
-rw-r--r--src/reader.go36
2 files changed, 34 insertions, 4 deletions
diff --git a/src/constants.go b/src/constants.go
index c568932d..9c635ea5 100644
--- a/src/constants.go
+++ b/src/constants.go
@@ -62,8 +62,6 @@ func init() {
defaultCommand = `set -o pipefail; command find -L . -mindepth 1 \( -path '*/\.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \) -prune -o -type f -print -o -type l -print 2> /dev/null | cut -b3-`
} else if os.Getenv("TERM") == "cygwin" {
defaultCommand = `sh -c "command find -L . -mindepth 1 -path '*/\.*' -prune -o -type f -print -o -type l -print 2> /dev/null | cut -b3-"`
- } else {
- defaultCommand = `for /r %P in (*) do @(set "_curfile=%P" & set "_curfile=!_curfile:%__CD__%=!" & echo !_curfile!)`
}
}
diff --git a/src/reader.go b/src/reader.go
index b388411b..7ed5cfce 100644
--- a/src/reader.go
+++ b/src/reader.go
@@ -2,14 +2,17 @@ package fzf
import (
"bufio"
+ "context"
"io"
"os"
"os/exec"
+ "path/filepath"
"sync"
"sync/atomic"
"time"
"github.com/junegunn/fzf/src/util"
+ "github.com/saracen/walker"
)
// Reader reads from command or standard input
@@ -78,7 +81,7 @@ func (r *Reader) terminate() {
r.killed = true
if r.exec != nil && r.exec.Process != nil {
util.KillCommand(r.exec)
- } else {
+ } else if defaultCommand != "" {
os.Stdin.Close()
}
}
@@ -99,7 +102,11 @@ func (r *Reader) ReadSource() {
shell := "bash"
cmd := os.Getenv("FZF_DEFAULT_COMMAND")
if len(cmd) == 0 {
- success = r.readFromCommand(&shell, defaultCommand)
+ if defaultCommand != "" {
+ success = r.readFromCommand(&shell, defaultCommand)
+ } else {
+ success = r.readFiles()
+ }
} else {
success = r.readFromCommand(nil, cmd)
}
@@ -144,6 +151,31 @@ func (r *Reader) readFromStdin() bool {
return true
}
+func (r *Reader) readFiles() bool {
+ r.killed = false
+ fn := func(path string, mode os.FileInfo) error {
+ path = filepath.Clean(path)
+ if path != "." {
+ if mode.Mode().IsDir() && filepath.Base(path)[0] == '.' {
+ return filepath.SkipDir
+ }
+ if r.pusher([]byte(path)) {
+ atomic.StoreInt32(&r.event, int32(EvtReadNew))
+ }
+ }
+ r.mutex.Lock()
+ defer r.mutex.Unlock()
+ if r.killed {
+ return context.Canceled
+ }
+ return nil
+ }
+ cb := walker.WithErrorCallback(func(pathname string, err error) error {
+ return nil
+ })
+ return walker.Walk(".", fn, cb) == nil
+}
+
func (r *Reader) readFromCommand(shell *string, command string) bool {
r.mutex.Lock()
r.killed = false