Skip to content
Myr

Add --walker-path-sep=CHAR to use a different path separator

Before adoption: this commit came in with the history the project adopted, so no landing records it.

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

authored by Junegunn Choi · committed by Junegunn Choi · parent a067458 · Browse files · 5 files+44 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+44 added−6 removed

  • other:+44 added−6 removed

5 files+44 added−6 removed

modified:man/man1/fzf.1+4 added
1006 unmodified lines
1007.B "\-\-walker\-skip=DIRS"1008Comma-separated list of directory names to skip during the directory walk.1009The default value is \fB.git,node_modules\fR.10101011.TP1012.B "\-\-walker\-path\-sep=CHAR"1013Path separator to use (default: '/' on Unix, '\\' on Windows)10141015.SS Shell integration1016.TP1017.B "\-\-bash"1018Print script to set up Bash shell integration
673 unmodified lines
modified:src/core.go+2 added-2 removed
157 unmodified lines
158 if reloadOnStart {159 // reload or reload-sync action is bound to 'start' event, no need to start the reader160 eventBox.Set(EvtReadNone, nil)161 } else {162 go reader.ReadSource(opts.Input, opts.WalkerRoot, opts.WalkerOpts, opts.WalkerSkip)162 go reader.ReadSource(opts.Input, opts.WalkerRoot, opts.WalkerOpts, opts.WalkerSkip, opts.WalkerSep)163 }164 }165166 // Matcher
44 unmodified lines
211 mutex.Unlock()212 }213 return false214 }, eventBox, executor, opts.ReadZero, false)215 reader.ReadSource(opts.Input, opts.WalkerRoot, opts.WalkerOpts, opts.WalkerSkip)215 reader.ReadSource(opts.Input, opts.WalkerRoot, opts.WalkerOpts, opts.WalkerSkip, opts.WalkerSep)216 } else {217 eventBox.Unwatch(EvtReadNew)218 eventBox.WaitFor(EvtReadFin)219
238 unmodified lines
modified:src/options.go+23 added
145 unmodified lines
146 --walker=OPTS [file][,dir][,follow][,hidden] (default: file,follow,hidden)147 --walker-root=DIR Root directory from which to start walker (default: .)148 --walker-skip=DIRS Comma-separated list of directory names to skip149 (default: .git,node_modules)150 --walker-path-sep=CHAR Path separator to use (default: / on Unix, \ on Windows)151152 Shell integration153 --bash Print script to set up Bash shell integration154 --zsh Print script to set up Zsh shell integration
334 unmodified lines
489 ClearOnExit bool490 WalkerOpts walkerOpts491 WalkerRoot string492 WalkerSkip []string493 WalkerSep byte494 Version bool495 Help bool496 CPUProfile string497 MEMProfile string
95 unmodified lines
593 ClearOnExit: true,594 WalkerOpts: walkerOpts{file: true, hidden: true, follow: true},595 WalkerRoot: ".",596 WalkerSkip: []string{".git", "node_modules"},597 WalkerSep: os.PathSeparator,598 Help: false,599 Version: false}600}601
1304 unmodified lines
1906 }1907 return &result, nil1908}19091910func parsePathSep(str string) (byte, error) {1911 bytes := []byte(str)1912 if len(bytes) != 1 {1913 return os.PathSeparator, errors.New("invalid path separator (expected: single-byte character)")1914 }1915 return bytes[0], nil1916}19171918func parseOptions(index *int, opts *Options, allArgs []string) error {1919 var err error1920 var historyMax int1921 if opts.History == nil {
567 unmodified lines
2489 if err != nil {2490 return err2491 }2492 opts.WalkerSkip = filterNonEmpty(strings.Split(str, ","))2493 case "--walker-path-sep":2494 str, err := nextString(allArgs, &i, "path separator required")2495 if err != nil {2496 return err2497 }2498 if opts.WalkerSep, err = parsePathSep(str); err != nil {2499 return err2500 }2501 case "--profile-cpu":2502 if opts.CPUProfile, err = nextString(allArgs, &i, "file path required: cpu"); err != nil {2503 return err2504 }
179 unmodified lines
2684 } else if match, value := optString(arg, "--walker-root="); match {2685 opts.WalkerRoot = value2686 } else if match, value := optString(arg, "--walker-skip="); match {2687 opts.WalkerSkip = filterNonEmpty(strings.Split(value, ","))2688 } else if match, value := optString(arg, "--walker-path-sep="); match {2689 if opts.WalkerSep, err = parsePathSep(value); err != nil {2690 return err2691 }2692 } else if match, value := optString(arg, "--hscroll-off="); match {2693 if opts.HscrollOff, err = atoi(value); err != nil {2694 return err2695 }
308 unmodified lines
modified:src/reader.go+13 added-4 removed
109 unmodified lines
110 return true111}112113// ReadSource reads data from the default command or from standard input114func (r *Reader) ReadSource(inputChan chan string, root string, opts walkerOpts, ignores []string) {114func (r *Reader) ReadSource(inputChan chan string, root string, opts walkerOpts, ignores []string, sep byte) {115 r.startEventPoller()116 var success bool117 if inputChan != nil {118 success = r.readChannel(inputChan)119 } else if util.IsTty(os.Stdin) {120 cmd := os.Getenv("FZF_DEFAULT_COMMAND")121 if len(cmd) == 0 {122 success = r.readFiles(root, opts, ignores)122 success = r.readFiles(root, opts, ignores, sep)123 } else {124 // We can't export FZF_* environment variables to the default command125 success = r.readFromCommand(cmd, nil)126 }
105 unmodified lines
232 }233 return false234}235236func (r *Reader) readFiles(root string, opts walkerOpts, ignores []string) bool {236func (r *Reader) readFiles(root string, opts walkerOpts, ignores []string, sep byte) bool {237 r.killed = false238 conf := fastwalk.Config{Follow: opts.follow}239 replaceSep := sep != os.PathSeparator240 fn := func(path string, de os.DirEntry, err error) error {241 if err != nil {242 return nil243 }
10 unmodified lines
254 return filepath.SkipDir255 }256 }257 }258 bytes := stringBytes(path)259 if replaceSep {260 for i, b := range bytes {261 if b == os.PathSeparator {262 bytes[i] = sep263 }264 }265 }257 if ((opts.file && !isDir) || (opts.dir && isDir)) && r.pusher([]byte(path)) {266 if ((opts.file && !isDir) || (opts.dir && isDir)) && r.pusher(bytes) {267 atomic.StoreInt32(&r.event, int32(EvtReadNew))268 }269 }270 r.mutex.Lock()
37 unmodified lines
modified:CHANGELOG.md+2 added
45 unmodified lines
46 fzf --header 'Loading ...' --header-lines 1 \47 --bind 'start:reload:sleep 1; ps -ef' \48 --bind 'load:change-header:Loaded!'49 ```50- Added `--walker-path-sep=CHAR` option to change the default path separator used by the built-in walker51 - Needed when running a Windows binary on WSL or zsh on Windows where forward slashes are expected52- Fixed mouse support on Windows53- Fixed crash when using `--tiebreak=end` with very long items54- zsh 5.0 compatibility (thanks to @LangLangBart)55- Fixed `--walker-skip` to also skip symlinks to directories
2150 unmodified lines