summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/constants.go11
-rw-r--r--src/reader.go38
2 files changed, 11 insertions, 38 deletions
diff --git a/src/constants.go b/src/constants.go
index 76211dcd..f5f8a939 100644
--- a/src/constants.go
+++ b/src/constants.go
@@ -2,7 +2,6 @@ package fzf
import (
"math"
- "os"
"time"
"github.com/junegunn/fzf/src/util"
@@ -54,16 +53,6 @@ const (
defaultJumpLabels string = "asdfghjklqwertyuiopzxcvbnm1234567890ASDFGHJKLQWERTYUIOPZXCVBNM`~;:,<.>/?'\"!@#$%^&*()[{]}-_=+"
)
-var defaultCommand string
-
-func init() {
- if !util.IsWindows() {
- 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-"`
- }
-}
-
// fzf events
const (
EvtReadNew util.EventType = iota
diff --git a/src/reader.go b/src/reader.go
index 494a2f72..ce5950d7 100644
--- a/src/reader.go
+++ b/src/reader.go
@@ -6,14 +6,13 @@ import (
"io"
"os"
"os/exec"
- "path"
"path/filepath"
"sync"
"sync/atomic"
"time"
+ "github.com/charlievieth/fastwalk"
"github.com/junegunn/fzf/src/util"
- "github.com/saracen/walker"
)
// Reader reads from command or standard input
@@ -77,14 +76,13 @@ func (r *Reader) fin(success bool) {
func (r *Reader) terminate() {
r.mutex.Lock()
- defer func() { r.mutex.Unlock() }()
-
r.killed = true
if r.exec != nil && r.exec.Process != nil {
util.KillCommand(r.exec)
- } else if defaultCommand != "" {
+ } else {
os.Stdin.Close()
}
+ r.mutex.Unlock()
}
func (r *Reader) restart(command string) {
@@ -99,24 +97,9 @@ func (r *Reader) ReadSource() {
r.startEventPoller()
var success bool
if util.IsTty() {
- // The default command for *nix requires a shell that supports "pipefail"
- // https://unix.stackexchange.com/a/654932/62171
- shell := "bash"
- currentShell := os.Getenv("SHELL")
- currentShellName := path.Base(currentShell)
- for _, shellName := range []string{"bash", "zsh", "ksh", "ash", "hush", "mksh", "yash"} {
- if currentShellName == shellName {
- shell = currentShell
- break
- }
- }
cmd := os.Getenv("FZF_DEFAULT_COMMAND")
if len(cmd) == 0 {
- if defaultCommand != "" {
- success = r.readFromCommand(&shell, defaultCommand)
- } else {
- success = r.readFiles()
- }
+ success = r.readFiles()
} else {
success = r.readFromCommand(nil, cmd)
}
@@ -163,10 +146,14 @@ func (r *Reader) readFromStdin() bool {
func (r *Reader) readFiles() bool {
r.killed = false
- fn := func(path string, mode os.FileInfo) error {
+ conf := fastwalk.Config{Follow: true}
+ fn := func(path string, de os.DirEntry, err error) error {
+ if err != nil {
+ return nil
+ }
path = filepath.Clean(path)
if path != "." {
- isDir := mode.Mode().IsDir()
+ isDir := de.IsDir()
if isDir && filepath.Base(path)[0] == '.' {
return filepath.SkipDir
}
@@ -181,10 +168,7 @@ func (r *Reader) readFiles() bool {
}
return nil
}
- cb := walker.WithErrorCallback(func(pathname string, err error) error {
- return nil
- })
- return walker.Walk(".", fn, cb) == nil
+ return fastwalk.Walk(&conf, ".", fn) == nil
}
func (r *Reader) readFromCommand(shell *string, command string) bool {