summaryrefslogtreecommitdiff
path: root/src/reader.go
diff options
context:
space:
mode:
authormattn <mattn.jp@gmail.com>2020-02-04 12:31:00 +0900
committerGitHub <noreply@github.com>2020-02-04 12:31:00 +0900
commit311b78ae82fc8b06f0eefbd54d6290f3a40d5e23 (patch)
tree563fb2acaf5a59c2562681d6b98135d92ccb263f /src/reader.go
parentf5cf4fc8fbfbe6e02cb1ee700c035c073db4a5cb (diff)
downloadfzf-311b78ae82fc8b06f0eefbd54d6290f3a40d5e23.tar.gz
[windows] Use native walker since output of DOS command is not UTF-8 encoded (#1847)
Makes scanning 300x faster on Windows
Diffstat (limited to 'src/reader.go')
-rw-r--r--src/reader.go36
1 files changed, 34 insertions, 2 deletions
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