Skip to content
Myr

Add walker options and replace 'find' with the built-in walker (#3649)

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

authored by Junegunn Choi · committed by GitHub · parent 6ce8d49 · Browse files · 12 files+230 added−98 removed
This commit

State

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

Diff stats

12 files+230 added−98 removed

  • other:+230 added−98 removed

12 files+230 added−98 removed

modified:bin/fzf-tmux+3 added-2 removed
194 unmodified lines
195 echo "fzf-tmux: tmux 3.2 or above is required for popup mode" >&2196 exit 2197 fi198fi199[[ -n "$FZF_DEFAULT_OPTS" ]] && envs="$envs FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS")"200[[ -n "$FZF_DEFAULT_COMMAND" ]] && envs="$envs FZF_DEFAULT_COMMAND=$(printf %q "$FZF_DEFAULT_COMMAND")"199envs="$envs FZF_DEFAULT_COMMAND=$(printf %q "$FZF_DEFAULT_COMMAND")"200envs="$envs FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS")"201envs="$envs FZF_DEFAULT_OPTS_FILE=$(printf %q "$FZF_DEFAULT_OPTS_FILE")"202[[ -n "$RUNEWIDTH_EASTASIAN" ]] && envs="$envs RUNEWIDTH_EASTASIAN=$(printf %q "$RUNEWIDTH_EASTASIAN")"203[[ -n "$BAT_THEME" ]] && envs="$envs BAT_THEME=$(printf %q "$BAT_THEME")"204echo "$envs;" > "$argsf"205
37 unmodified lines
modified:man/man1/fzf.1+28 added-2 removed
618 unmodified lines
619The following example uses https://github.com/junegunn/fzf/blob/master/bin/fzf-preview.sh620script to render an image using either of the protocols inside the preview window.621622e.g.623 \fBfzf --preview='fzf-preview.sh {}'623 \fBfzf --preview='fzf-preview.sh {}'\fR624625.RE626627.TP
225 unmodified lines
853.TP854.B "--version"855Display version information and exit856857.SS Directory traversal858.TP858Note that most options have the opposite versions with \fB--no-\fR prefix.859.B "--walker=[file][,dir][,follow][,hidden]"860Determines the behavior of the built-in directory walker that is used when861\fB$FZF_DEFAULT_COMMAND\fR is not set. The default value is \fBfile,follow,hidden\fR.862863* \fBfile\fR: Include files in the search result864.br865* \fBdir\fR: Include directories in the search result866.br867* \fBhidden\fR: Include and follow hidden directories868.br869* \fBfollow\fR: Follow symbolic links870.br871872.TP873.B "--walker-root=DIR"874The root directory from which to start the built-in directory walker.875The default value is the current working directory.876877.TP878.B "--walker-skip=DIRS"879Comma-separated list of directory names to skip during the directory walk.880The default value is \fB.git,node_modules\fR.881882.SS Note883.TP884Most options have the opposite versions with \fB--no-\fR prefix.885886.SH ENVIRONMENT VARIABLES887.TP888.B FZF_DEFAULT_COMMAND889Default command to use when input is tty. On *nix systems, fzf runs the command
609 unmodified lines
modified:shell/completion.bash+25 added-19 removed
11 unmodified lines
12[[ $- =~ i ]] || return 0131415# To use custom commands instead of find, override _fzf_compgen_{path,dir}16if ! declare -F _fzf_compgen_path > /dev/null; then17 _fzf_compgen_path() {18 echo "$1"19 command find -L "$1" \20 -name .git -prune -o -name .hg -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \21 -a -not -path "$1" -print 2> /dev/null | command sed 's@^\./@@'22 }23fi16#17# _fzf_compgen_path() {18# echo "$1"19# command find -L "$1" \20# -name .git -prune -o -name .hg -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \21# -a -not -path "$1" -print 2> /dev/null | command sed 's@^\./@@'22# }23#24# _fzf_compgen_dir() {25# command find -L "$1" \26# -name .git -prune -o -name .hg -prune -o -name .svn -prune -o -type d \27# -a -not -path "$1" -print 2> /dev/null | command sed 's@^\./@@'28# }2925if ! declare -F _fzf_compgen_dir > /dev/null; then26 _fzf_compgen_dir() {27 command find -L "$1" \28 -name .git -prune -o -name .hg -prune -o -name .svn -prune -o -type d \29 -a -not -path "$1" -print 2> /dev/null | command sed 's@^\./@@'30 }31fi3230###########################################################3132# To redraw line after fzf closes (printf '\e[5n')33bind '"\e[0n": redraw-current-line' 2> /dev/null
298 unmodified lines
332 leftover=${base/#"$dir"}333 leftover=${leftover/#\/}334 [[ -z "$dir" ]] && dir='.'335 [[ "$dir" != "/" ]] && dir="${dir/%\//}"336 matches=$(337 unset FZF_DEFAULT_COMMAND338 export FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --scheme=path --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_COMPLETION_OPTS-} $2"339 if declare -F "$1" > /dev/null; then340 eval "$1 $(printf %q "$dir")" | __fzf_comprun "$4" -q "$leftover"341 else342 [[ $1 =~ dir ]] && walker=dir,follow || walker=file,dir,follow,hidden343 __fzf_comprun "$4" -q "$leftover" --walker "$walker" --walker-root="$dir"339 matches=$(eval "$1 $(printf %q "$dir")" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --scheme=path --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_COMPLETION_OPTS-} $2" __fzf_comprun "$4" -q "$leftover" | while read -r item; do340 printf "%q " "${item%$3}$3"341 done)344 fi | while read -r item; do345 printf "%q " "${item%$3}$3"346 done347 )348 matches=${matches% }349 [[ -z "$3" ]] && [[ "${__fzf_nospace_commands-}" = *" ${COMP_WORDS[0]} "* ]] && matches="$matches "350 if [[ -n "$matches" ]]; then351 COMPREPLY=( "$matches" )
223 unmodified lines
modified:shell/completion.zsh+26 added-20 removed
75 unmodified lines
76# `finally` in lesser languages. We use it to *always* restore user options.77{7879# To use custom commands instead of find, override _fzf_compgen_{path,dir}80if ! declare -f _fzf_compgen_path > /dev/null; then81 _fzf_compgen_path() {82 echo "$1"83 command find -L "$1" \84 -name .git -prune -o -name .hg -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \85 -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'86 }87fi80#81# _fzf_compgen_path() {82# echo "$1"83# command find -L "$1" \84# -name .git -prune -o -name .hg -prune -o -name .svn -prune -o \( -type d -o -type f -o -type l \) \85# -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'86# }87#88# _fzf_compgen_dir() {89# command find -L "$1" \90# -name .git -prune -o -name .hg -prune -o -name .svn -prune -o -type d \91# -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'92# }9389if ! declare -f _fzf_compgen_dir > /dev/null; then90 _fzf_compgen_dir() {91 command find -L "$1" \92 -name .git -prune -o -name .hg -prune -o -name .svn -prune -o -type d \93 -a -not -path "$1" -print 2> /dev/null | sed 's@^\./@@'94 }95fi9694###########################################################9596__fzf_comprun() {97 if [[ "$(type _fzf_comprun 2>&1)" =~ function ]]; then
46 unmodified lines
144 leftover=${base/#"$dir"}145 leftover=${leftover/#\/}146 [ -z "$dir" ] && dir='.'147 [ "$dir" != "/" ] && dir="${dir/%\//}"148 matches=$(149 unset FZF_DEFAULT_COMMAND150 export FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --scheme=path --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_COMPLETION_OPTS-}"151 if declare -f "$compgen" > /dev/null; then152 eval "$compgen $(printf %q "$dir")" | __fzf_comprun "$cmd" ${(Q)${(Z+n+)fzf_opts}} -q "$leftover"153 else154 [[ $compgen =~ dir ]] && walker=dir,follow || walker=file,dir,follow,hidden155 __fzf_comprun "$cmd" ${(Q)${(Z+n+)fzf_opts}} -q "$leftover" --walker "$walker" --walker-root="$dir" < /dev/tty151 matches=$(eval "$compgen $(printf %q "$dir")" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --scheme=path --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_COMPLETION_OPTS-}" __fzf_comprun "$cmd" ${(Q)${(Z+n+)fzf_opts}} -q "$leftover" | while read item; do152 item="${item%$suffix}$suffix"153 echo -n "${(q)item} "154 done)156 fi | while read item; do157 item="${item%$suffix}$suffix"158 echo -n "${(q)item} "159 done160 )161 matches=${matches% }162 if [ -n "$matches" ]; then163 LBUFFER="$lbuf$matches$tail"164 fi
189 unmodified lines
modified:shell/key-bindings.bash+8 added-13 removed
modified:shell/key-bindings.fish+6 added-15 removed
23 unmodified lines
24 set -l dir $commandline[1]25 set -l fzf_query $commandline[2]26 set -l prefix $commandline[3]2728 # "-path \$dir'*/.*'" matches hidden files/folders inside $dir but not29 # $dir itself, even if hidden.30 test -n "$FZF_CTRL_T_COMMAND"; or set -l FZF_CTRL_T_COMMAND "31 command find -L \$dir -mindepth 1 \\( -path \$dir'*/.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \32 -o -type f -print \33 -o -type d -print \34 -o -type l -print 2> /dev/null | sed 's@^\./@@'"3528 test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%29 begin38 set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT --reverse --scheme=path --bind=ctrl-z:ignore $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS"39 eval "$FZF_CTRL_T_COMMAND | "(__fzfcmd)' -m --query "'$fzf_query'"' | while read -l r; set result $result $r; end30 set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT --reverse --walker=file,dir,follow,hidden --scheme=path --bind=ctrl-z:ignore $FZF_DEFAULT_OPTS $FZF_CTRL_T_OPTS"31 set -lx FZF_DEFAULT_COMMAND "$FZF_CTRL_T_COMMAND"32 eval (__fzfcmd)' -m --query "'$fzf_query'"' | while read -l r; set result $result $r; end33 end34 if [ -z "$result" ]35 commandline -f repaint36 return
36 unmodified lines
73 set -l dir $commandline[1]74 set -l fzf_query $commandline[2]75 set -l prefix $commandline[3]7684 test -n "$FZF_ALT_C_COMMAND"; or set -l FZF_ALT_C_COMMAND "85 command find -L \$dir -mindepth 1 \\( -path \$dir'*/.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' \\) -prune \86 -o -type d -print 2> /dev/null | sed 's@^\./@@'"77 test -n "$FZF_TMUX_HEIGHT"; or set FZF_TMUX_HEIGHT 40%78 begin89 set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT --reverse --scheme=path --bind=ctrl-z:ignore $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS"90 eval "$FZF_ALT_C_COMMAND | "(__fzfcmd)' +m --query "'$fzf_query'"' | read -l result79 set -lx FZF_DEFAULT_OPTS "--height $FZF_TMUX_HEIGHT --reverse --walker=dir,follow,hidden --scheme=path --bind=ctrl-z:ignore $FZF_DEFAULT_OPTS $FZF_ALT_C_OPTS"80 set -lx FZF_DEFAULT_COMMAND "$FZF_ALT_C_COMMAND"81 eval (__fzfcmd)' +m --query "'$fzf_query'"' | read -l result8283 if [ -n "$result" ]84 cd -- $result85
81 unmodified lines
modified:shell/key-bindings.zsh+2 added-8 removed
39 unmodified lines
40{4142# CTRL-T - Paste the selected file path(s) into the command line43__fsel() {44 local cmd="${FZF_CTRL_T_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \45 -o -type f -print \46 -o -type d -print \47 -o -type l -print 2> /dev/null | cut -b3-"}"44 setopt localoptions pipefail no_aliases 2> /dev/null45 local item50 eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --scheme=path --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_CTRL_T_OPTS-}" $(__fzfcmd) -m "$@" | while read item; do46 FZF_DEFAULT_COMMAND=${FZF_CTRL_T_COMMAND:-} FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --walker=file,dir,follow,hidden --scheme=path --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_CTRL_T_OPTS-}" $(__fzfcmd) -m "$@" < /dev/tty | while read item; do47 echo -n "${(q)item} "48 done49 local ret=$?50 echo
17 unmodified lines
68bindkey -M viins '^T' fzf-file-widget6970# ALT-C - cd into the selected directory71fzf-cd-widget() {76 local cmd="${FZF_ALT_C_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \77 -o -type d -print 2> /dev/null | cut -b3-"}"72 setopt localoptions pipefail no_aliases 2> /dev/null79 local dir="$(eval "$cmd" | FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --scheme=path --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_ALT_C_OPTS-}" $(__fzfcmd) +m)"73 local dir="$(FZF_DEFAULT_COMMAND=${FZF_ALT_C_COMMAND:-} FZF_DEFAULT_OPTS="--height ${FZF_TMUX_HEIGHT:-40%} --reverse --walker=dir,follow,hidden --scheme=path --bind=ctrl-z:ignore ${FZF_DEFAULT_OPTS-} ${FZF_ALT_C_OPTS-}" $(__fzfcmd) +m < /dev/tty)"74 if [[ -z "$dir" ]]; then75 zle redisplay76 return 077 fi
40 unmodified lines
modified:src/core.go+2 added-2 removed
115 unmodified lines
116 if !streamingFilter {117 reader = NewReader(func(data []byte) bool {118 return chunkList.Push(data)119 }, eventBox, opts.ReadZero, opts.Filter == nil)120 go reader.ReadSource()120 go reader.ReadSource(opts.WalkerRoot, opts.WalkerOpts, opts.WalkerSkip)121 }122123 // Matcher124 forward := true
39 unmodified lines
164 }165 }166 return false167 }, eventBox, opts.ReadZero, false)168 reader.ReadSource()168 reader.ReadSource(opts.WalkerRoot, opts.WalkerOpts, opts.WalkerSkip)169 } else {170 eventBox.Unwatch(EvtReadNew)171 eventBox.WaitFor(EvtReadFin)172
211 unmodified lines
modified:src/options.go+65 added
122 unmodified lines
123 --listen[=[ADDR:]PORT] Start HTTP server to receive actions (POST /)124 (To allow remote process execution, use --listen-unsafe)125 --version Display version information and exit126127 Directory traversal (Only used when $FZF_DEFAULT_COMMAND is not set)128 --walker=OPTS [file][,dir][,follow][,hidden] (default: file,follow,hidden)129 --walker-root=DIR Root directory from which to start walker (default: .)130 --walker-skip=DIRS Comma-separated list of directory names to skip131 (default: .git,node_modules)132133 Environment variables134 FZF_DEFAULT_COMMAND Default command to use when input is tty135 FZF_DEFAULT_OPTS Default options (e.g. '--layout=reverse --info=inline')136 FZF_DEFAULT_OPTS_FILE Location of the file to read default options from
142 unmodified lines
279func firstLine(s string) string {280 return strings.SplitN(s, "\n", 2)[0]281}282283type walkerOpts struct {284 file bool285 dir bool286 hidden bool287 follow bool288}289290// Options stores the values of command-line options291type Options struct {292 Fuzzy bool293 FuzzyAlgo algo.Algo
60 unmodified lines
354 Tabstop int355 ListenAddr *listenAddress356 Unsafe bool357 ClearOnExit bool358 WalkerOpts walkerOpts359 WalkerRoot string360 WalkerSkip []string361 Version bool362}363364func filterNonEmpty(input []string) []string {365 output := make([]string, 0, len(input))366 for _, str := range input {367 if len(str) > 0 {368 output = append(output, str)369 }370 }371 return output372}373374func defaultPreviewOpts(command string) previewOpts {375 return previewOpts{command, posRight, sizeSpec{50, true}, "", false, false, false, false, tui.DefaultBorderShape, 0, 0, nil}376}377
60 unmodified lines
438 BorderLabel: labelOpts{},439 PreviewLabel: labelOpts{},440 Unsafe: false,441 ClearOnExit: true,442 WalkerOpts: walkerOpts{file: true, hidden: true, follow: true},443 WalkerRoot: ".",444 WalkerSkip: []string{".git", "node_modules"},445 Version: false}446}447448func help(code int) {
545 unmodified lines
994 }995 return theme996}997998func parseWalkerOpts(str string) walkerOpts {999 opts := walkerOpts{}1000 for _, str := range strings.Split(strings.ToLower(str), ",") {1001 switch str {1002 case "file":1003 opts.file = true1004 case "dir":1005 opts.dir = true1006 case "hidden":1007 opts.hidden = true1008 case "follow":1009 opts.follow = true1010 case "":1011 // Ignored1012 default:1013 errorExit("invalid walker option: " + str)1014 }1015 }1016 if !opts.file && !opts.dir {1017 errorExit("at least one of 'file' or 'dir' should be specified")1018 }1019 return opts1020}10211022var (1023 executeRegexp *regexp.Regexp1024 splitRegexp *regexp.Regexp1025 actionNameRegexp *regexp.Regexp
906 unmodified lines
1932 case "--clear":1933 opts.ClearOnExit = true1934 case "--no-clear":1935 opts.ClearOnExit = false1936 case "--walker":1937 opts.WalkerOpts = parseWalkerOpts(nextString(allArgs, &i, "walker options required [file][,dir][,follow][,hidden]"))1938 case "--walker-root":1939 opts.WalkerRoot = nextString(allArgs, &i, "directory required")1940 case "--walker-skip":1941 opts.WalkerSkip = filterNonEmpty(strings.Split(nextString(allArgs, &i, "directory names to ignore required"), ","))1942 case "--version":1943 opts.Version = true1944 case "--":1945 // Ignored
89 unmodified lines
2035 errorExit(err.Error())2036 }2037 opts.ListenAddr = &addr2038 opts.Unsafe = true2039 } else if match, value := optString(arg, "--walker="); match {2040 opts.WalkerOpts = parseWalkerOpts(value)2041 } else if match, value := optString(arg, "--walker-root="); match {2042 opts.WalkerRoot = value2043 } else if match, value := optString(arg, "--walker-skip="); match {2044 opts.WalkerSkip = filterNonEmpty(strings.Split(value, ","))2045 } else if match, value := optString(arg, "--hscroll-off="); match {2046 opts.HscrollOff = atoi(value)2047 } else if match, value := optString(arg, "--scroll-off="); match {2048 opts.ScrollOff = atoi(value)
223 unmodified lines
modified:src/reader.go+16 added-8 removed
91 unmodified lines
92 r.fin(success)93}9495// ReadSource reads data from the default command or from standard input96func (r *Reader) ReadSource() {96func (r *Reader) ReadSource(root string, opts walkerOpts, ignores []string) {97 r.startEventPoller()98 var success bool99 if util.IsTty() {100 cmd := os.Getenv("FZF_DEFAULT_COMMAND")101 if len(cmd) == 0 {102 success = r.readFiles()102 success = r.readFiles(root, opts, ignores)103 } else {104 // We can't export FZF_* environment variables to the default command105 success = r.readFromCommand(cmd, nil)106 }
37 unmodified lines
144 r.feed(os.Stdin)145 return true146}147148func (r *Reader) readFiles() bool {148func (r *Reader) readFiles(root string, opts walkerOpts, ignores []string) bool {149 r.killed = false150 conf := fastwalk.Config{Follow: true}150 conf := fastwalk.Config{Follow: opts.follow}151 fn := func(path string, de os.DirEntry, err error) error {152 if err != nil {153 return nil154 }155 path = filepath.Clean(path)156 if path != "." {157 isDir := de.IsDir()158 if isDir {159 base := filepath.Base(path)158 if isDir && filepath.Base(path)[0] == '.' {159 return filepath.SkipDir160 if !opts.hidden && base[0] == '.' {161 return filepath.SkipDir162 }163 for _, ignore := range ignores {164 if ignore == base {165 return filepath.SkipDir166 }167 }168 }161 if !isDir && r.pusher([]byte(path)) {169 if ((opts.file && !isDir) || (opts.dir && isDir)) && r.pusher([]byte(path)) {170 atomic.StoreInt32(&r.event, int32(EvtReadNew))171 }172 }173 r.mutex.Lock()
2 unmodified lines
176 return context.Canceled177 }178 return nil179 }172 return fastwalk.Walk(&conf, ".", fn) == nil180 return fastwalk.Walk(&conf, root, fn) == nil181}182183func (r *Reader) readFromCommand(command string, environ []string) bool {184 r.mutex.Lock()
19 unmodified lines
modified:CHANGELOG.md+34 added-4 removed
1CHANGELOG2=========340.48.05------6- Added options for customizing the behavior of the built-in walker7 | Option | Description | Default |8 | --- | --- | --- |9 | `--walker=OPTS` | Walker options (`[file][,dir][,follow][,hidden]`) | `file,follow,hidden` |10 | `--walker-root=DIR` | Root directory from which to start walker | `.` |11 | `--walker-skip=DIRS` | Comma-separated list of directory names to skip | `.git,node_modules` |12 - Examples13 ```sh14 # Built-in walker is only used by standalone fzf when $FZF_DEFAULT_COMMAND is not set15 unset FZF_DEFAULT_COMMAND1617 fzf # default: --walker=file,follow,hidden --walker-root=. --walker-skip=.git,node_modules18 fzf --walker=file,dir,hidden,follow --walker-skip=.git,node_modules,target1920 # Walker options in $FZF_DEFAULT_OPTS21 export FZF_DEFAULT_OPTS="--walker=file,dir,hidden,follow --walker-skip=.git,node_modules,target"22 fzf2324 # Reading from STDIN; --walker is ignored25 seq 100 | fzf --walker=dir2627 # Reading from $FZF_DEFAULT_COMMAND; --walker is ignored28 export FZF_DEFAULT_COMMAND='seq 100'29 fzf --walker=dir30 ```31- The shell extensions (key bindings and fuzzy completion) have been updated to use the built-in walker with these new options and they are now much faster out of the box.32330.47.034------6- Replaced ["the default find command"][find] with a built-in directory traversal to simplify the code and to achieve better performance and consistent behavior across platforms.35- Replaced ["the default find command"][find] with a built-in directory walker to simplify the code and to achieve better performance and consistent behavior across platforms.36 This doesn't affect you if you have `$FZF_DEFAULT_COMMAND` set.37 - Breaking changes:38 - Unlike [the previous "find" command][find], the new traversal code will list hidden files, but hidden directories will still be ignored39 - No filtering of `devtmpfs` or `proc` types40 - Traversal is parallelized, so the order of the entries will be different each time12 - You would wonder why fzf implements directory traversal anyway when it's a filter program following the Unix philosophy.13 But fzf has had [the traversal code for years][walker] to tackle the performance problem on Windows. And I decided to use the same approach on different platforms as well for the benefits listed above.14 - Built-in traversal is now done using the excellent [charlievieth/fastwalk][fastwalk] library, which easily outperforms its competitors and supports safely following symlinks.41 - You may wonder why fzf implements directory walker anyway when it's a filter program following the [Unix philosophy][unix].42 But fzf has had [the walker code for years][walker] to tackle the performance problem on Windows. And I decided to use the same approach on different platforms as well for the benefits listed above.43 - Built-in walker is using the excellent [charlievieth/fastwalk][fastwalk] library, which easily outperforms its competitors and supports safely following symlinks.44- Added `$FZF_DEFAULT_OPTS_FILE` to allow managing default options in a file45 - See [#3618](https://github.com/junegunn/fzf/pull/3618)46 - Option precedence from lower to higher47 1. Options read from `$FZF_DEFAULT_OPTS_FILE`
3 unmodified lines
5152[find]: https://github.com/junegunn/fzf/blob/0.46.1/src/constants.go#L60-L6453[walker]: https://github.com/junegunn/fzf/pull/184754[fastwalk]: https://github.com/charlievieth/fastwalk55[unix]: https://en.wikipedia.org/wiki/Unix_philosophy56570.46.158------59- Bug fixes and improvements
1861 unmodified lines
modified:README.md+15 added-5 removed
229 unmodified lines
230find * -type f | fzf > selected231```232233Without STDIN pipe, fzf will traverse the file system under the current234directory to get the list of files, skipping hidden directories. (You can235override the default behavior with `FZF_DEFAULT_COMMAND`)234directory to get the list of files.235236```sh237vim $(fzf)238```239240> You can override the default behavior241> * Either by setting `$FZF_DEFAULT_COMMAND` to a command that generates the desired list242> * Or by setting `--walker`, `--walker-root`, and `--walker-skip` options in `$FZF_DEFAULT_OPTS`243244> *:bulb: A more robust solution would be to use `xargs` but we've presented245> the above as it's easier to grasp*246> ```sh247> fzf --print0 | xargs -0 -o vim
142 unmodified lines
390The install script will setup the following key bindings for bash, zsh, and391fish.392393- `CTRL-T` - Paste the selected files and directories onto the command-line391 - Set `FZF_CTRL_T_COMMAND` to override the default command394 - The list is generated using `--walker file,dir,follow,hidden` option395 - You can override the behavior by setting `FZF_CTRL_T_COMMAND` to a custom command that generates the desired list396 - Or you can set `--walker*` options in `FZF_CTRL_T_OPTS`397 - Set `FZF_CTRL_T_OPTS` to pass additional options to fzf398 ```sh399 # Preview file content using bat (https://github.com/sharkdp/bat)400 export FZF_CTRL_T_OPTS="401 --walker-skip .git,node_modules,target402 --preview 'bat -n --color=always {}'403 --bind 'ctrl-/:change-preview-window(down|hidden|)'"404 ```405- `CTRL-R` - Paste the selected command from history onto the command-line
10 unmodified lines
416 --color header:italic417 --header 'Press CTRL-Y to copy command into clipboard'"418 ```419- `ALT-C` - cd into the selected directory420 - The list is generated using `--walker dir,follow,hidden` option421 - Set `FZF_ALT_C_COMMAND` to override the default command422 - Or you can set `--walker-*` options in `FZF_ALT_C_OPTS`423 - Set `FZF_ALT_C_OPTS` to pass additional options to fzf424 ```sh425 # Print tree structure in the preview window418 export FZF_ALT_C_OPTS="--preview 'tree -C {}'"426 export FZF_ALT_C_OPTS="427 --walker-skip .git,node_modules,target428 --preview 'tree -C {}'"429 ```430431If you're on a tmux session, you can start fzf in a tmux split-pane or in432a tmux popup window by setting `FZF_TMUX_OPTS` (e.g. `export FZF_TMUX_OPTS='-p80%,60%'`).
363 unmodified lines
796797# Setting fd as the default source for fzf798export FZF_DEFAULT_COMMAND='fd --type f --strip-cwd-prefix'799790# Now fzf (w/o pipe) will use fd instead of find800# Now fzf (w/o pipe) will use the fd command to generate the list801fzf802803# To apply the command to CTRL-T as well804export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"
46 unmodified lines