diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2024-06-29 17:11:09 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2024-06-29 17:13:31 +0900 |
| commit | bf515a3d3251c54d04cd8e2e9f422cdd3f789fb8 (patch) | |
| tree | c618a7ed122d2c3174165838f8b8319576513b55 /src/reader.go | |
| parent | a06745826a4cba4f578a69258f9def75c59530fc (diff) | |
| download | fzf-bf515a3d3251c54d04cd8e2e9f422cdd3f789fb8.tar.gz | |
Add --walker-path-sep=CHAR to use a different path separator
This is needed when you run a Windows binary on WSL or zsh on Windows
where forward slashes are expected.
export FZF_DEFAULT_OPTS='--walker-path-sep /'
Close #3859
Diffstat (limited to 'src/reader.go')
| -rw-r--r-- | src/reader.go | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/reader.go b/src/reader.go index f39f47f5..9d4fe160 100644 --- a/src/reader.go +++ b/src/reader.go @@ -111,7 +111,7 @@ func (r *Reader) readChannel(inputChan chan string) bool { } // ReadSource reads data from the default command or from standard input -func (r *Reader) ReadSource(inputChan chan string, root string, opts walkerOpts, ignores []string) { +func (r *Reader) ReadSource(inputChan chan string, root string, opts walkerOpts, ignores []string, sep byte) { r.startEventPoller() var success bool if inputChan != nil { @@ -119,7 +119,7 @@ func (r *Reader) ReadSource(inputChan chan string, root string, opts walkerOpts, } else if util.IsTty(os.Stdin) { cmd := os.Getenv("FZF_DEFAULT_COMMAND") if len(cmd) == 0 { - success = r.readFiles(root, opts, ignores) + success = r.readFiles(root, opts, ignores, sep) } else { // We can't export FZF_* environment variables to the default command success = r.readFromCommand(cmd, nil) @@ -233,9 +233,10 @@ func isSymlinkToDir(path string, de os.DirEntry) bool { return false } -func (r *Reader) readFiles(root string, opts walkerOpts, ignores []string) bool { +func (r *Reader) readFiles(root string, opts walkerOpts, ignores []string, sep byte) bool { r.killed = false conf := fastwalk.Config{Follow: opts.follow} + replaceSep := sep != os.PathSeparator fn := func(path string, de os.DirEntry, err error) error { if err != nil { return nil @@ -254,7 +255,15 @@ func (r *Reader) readFiles(root string, opts walkerOpts, ignores []string) bool } } } - if ((opts.file && !isDir) || (opts.dir && isDir)) && r.pusher([]byte(path)) { + bytes := stringBytes(path) + if replaceSep { + for i, b := range bytes { + if b == os.PathSeparator { + bytes[i] = sep + } + } + } + if ((opts.file && !isDir) || (opts.dir && isDir)) && r.pusher(bytes) { atomic.StoreInt32(&r.event, int32(EvtReadNew)) } } |
