diff --git a/go.mod b/go.mod index 4ab4980..5ffa67a 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,7 @@ module github.com/junegunn/fzf require ( - github.com/charlievieth/fastwalk v1.0.4 + github.com/charlievieth/fastwalk v1.0.7-0.20240703190418-87029d931815 github.com/gdamore/tcell/v2 v2.7.4 github.com/mattn/go-isatty v0.0.20 github.com/mattn/go-shellwords v1.0.12 diff --git a/go.sum b/go.sum index c0ccde0..6cd4c53 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/charlievieth/fastwalk v1.0.4 h1:EG3y5L1XBa8VftvpONuQlfe5sNuf1xzGpm59bdgCDwo= -github.com/charlievieth/fastwalk v1.0.4/go.mod h1:JSfglY/gmL/rqsUS1NCsJTocB5n6sSl9ApAqif4CUbs= +github.com/charlievieth/fastwalk v1.0.7-0.20240703190418-87029d931815 h1:4PRbYm9OMgH0bcdZZqMXA/AoOvpGy4l0H6g9Au/kgGA= +github.com/charlievieth/fastwalk v1.0.7-0.20240703190418-87029d931815/go.mod h1:rV19+IF9Y2TYQNy4MqEk5M/spNHjKsA0i71yrsv2p4E= github.com/gdamore/encoding v1.0.0 h1:+7OoQ1Bc6eTm5niUzBa0Ctsh6JbMW6Ra+YNuAtDBdko= github.com/gdamore/encoding v1.0.0/go.mod h1:alR0ol34c49FCSBLjhosxzcPHQbf2trDkoo5dl+VrEg= github.com/gdamore/tcell/v2 v2.7.4 h1:sg6/UnTM9jGpZU+oFYAsDahfchWAFW8Xx2yFinNSAYU= diff --git a/src/reader.go b/src/reader.go index 9d4b2f4..b9368f0 100644 --- a/src/reader.go +++ b/src/reader.go @@ -233,14 +233,32 @@ func isSymlinkToDir(path string, de os.DirEntry) bool { return false } +func trimPath(path string) string { + bytes := stringBytes(path) + + for len(bytes) > 1 && bytes[0] == '.' && (bytes[1] == '/' || bytes[1] == '\\') { + bytes = bytes[2:] + } + + if len(bytes) == 0 { + return "." + } + + return byteString(bytes) +} + func (r *Reader) readFiles(root string, opts walkerOpts, ignores []string) bool { r.killed = false - conf := fastwalk.Config{Follow: opts.follow} + conf := fastwalk.Config{ + Follow: opts.follow, + // Use forward slashes when running a Windows binary under WSL or MSYS + ToSlash: fastwalk.DefaultToSlash(), + } fn := func(path string, de os.DirEntry, err error) error { if err != nil { return nil } - path = filepath.Clean(path) + path = trimPath(path) if path != "." { isDir := de.IsDir() if isDir || opts.follow && isSymlinkToDir(path, de) {