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
Provenance
- Commit
d282a16- Tree
ddab9c7- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
GitHub <noreply@github.com>- Parent
6ce8d49
12 files changed+230 added−98 removed
modified:bin/fzf-tmux+3 added-2 removed
194 unmodified lines195 echo "fzf-tmux: tmux 3.2 or above is required for popup mode" >&2196 exit 2197 fi198 fi199-[[ -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")"199+envs="$envs FZF_DEFAULT_COMMAND=$(printf %q "$FZF_DEFAULT_COMMAND")"200+envs="$envs FZF_DEFAULT_OPTS=$(printf %q "$FZF_DEFAULT_OPTS")"201+envs="$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")"204 echo "$envs;" > "$argsf"205 37 unmodified linesmodified:man/man1/fzf.1+28 added-2 removed
618 unmodified lines619 The following example uses https://github.com/junegunn/fzf/blob/master/bin/fzf-preview.sh620 script to render an image using either of the protocols inside the preview window.621 622 e.g.623- \fBfzf --preview='fzf-preview.sh {}'623+ \fBfzf --preview='fzf-preview.sh {}'\fR624 625 .RE626 627 .TP225 unmodified lines853 .TP854 .B "--version"855 Display version information and exit856 857+.SS Directory traversal858 .TP858-Note that most options have the opposite versions with \fB--no-\fR prefix.859+.B "--walker=[file][,dir][,follow][,hidden]"860+Determines 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.862 863+* \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+.br871+872+.TP873+.B "--walker-root=DIR"874+The root directory from which to start the built-in directory walker.875+The default value is the current working directory.876+877+.TP878+.B "--walker-skip=DIRS"879+Comma-separated list of directory names to skip during the directory walk.880+The default value is \fB.git,node_modules\fR.881+882+.SS Note883+.TP884+Most options have the opposite versions with \fB--no-\fR prefix.885+886 .SH ENVIRONMENT VARIABLES887 .TP888 .B FZF_DEFAULT_COMMAND889 Default command to use when input is tty. On *nix systems, fzf runs the command609 unmodified linesmodified:shell/completion.bash+25 added-19 removed
11 unmodified lines12 [[ $- =~ i ]] || return 013 14 15 # To use custom commands instead of find, override _fzf_compgen_{path,dir}16-if ! 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- }23-fi16+#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+# }29 25-if ! 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- }31-fi32-30 ###########################################################31 32 # To redraw line after fzf closes (printf '\e[5n')33 bind '"\e[0n": redraw-current-line' 2> /dev/null298 unmodified lines332 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 linesmodified:shell/completion.zsh+26 added-20 removed
75 unmodified lines76 # `finally` in lesser languages. We use it to *always* restore user options.77 {78 79 # To use custom commands instead of find, override _fzf_compgen_{path,dir}80-if ! 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- }87-fi80+#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+# }93 89-if ! 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- }95-fi96-94 ###########################################################95 96 __fzf_comprun() {97 if [[ "$(type _fzf_comprun 2>&1)" =~ function ]]; then46 unmodified lines144 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 fi189 unmodified linesmodified:shell/key-bindings.bash+8 added-13 removed
15 unmodified lines161718192021222324252627202122232425269 unmodified lines36373839454647484940414243444546474880 unmodified lines15 unmodified lines
# Key bindings# ------------__fzf_select__() { local cmd opts cmd="${FZF_CTRL_T_COMMAND:-"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 d -print \ -o -type l -print 2> /dev/null | command cut -b3-"}" opts="--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore --reverse --scheme=path ${FZF_DEFAULT_OPTS-} ${FZF_CTRL_T_OPTS-} -m" eval "$cmd" | FZF_DEFAULT_OPTS="$opts" $(__fzfcmd) "$@" | local opts opts="--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore --reverse --walker=file,dir,follow,hidden --scheme=path ${FZF_DEFAULT_OPTS-} ${FZF_CTRL_T_OPTS-} -m" FZF_DEFAULT_COMMAND=${FZF_CTRL_T_COMMAND:-} FZF_DEFAULT_OPTS="$opts" $(__fzfcmd) "$@" | while read -r item; do printf '%q ' "$item" # escape special chars done}9 unmodified lines READLINE_POINT=$(( READLINE_POINT + ${#selected} ))}
__fzf_cd__() { local cmd opts dir cmd="${FZF_ALT_C_COMMAND:-"command find -L . -mindepth 1 \\( -path '*/.*' -o -fstype 'sysfs' -o -fstype 'devfs' -o -fstype 'devtmpfs' -o -fstype 'proc' \\) -prune \ -o -type d -print 2> /dev/null | command cut -b3-"}" opts="--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore --reverse --scheme=path ${FZF_DEFAULT_OPTS-} ${FZF_ALT_C_OPTS-} +m" dir=$(set +o pipefail; eval "$cmd" | FZF_DEFAULT_OPTS="$opts" $(__fzfcmd)) && printf 'builtin cd -- %q' "$dir" local opts dir opts="--height ${FZF_TMUX_HEIGHT:-40%} --bind=ctrl-z:ignore --reverse --walker=dir,follow,hidden --scheme=path ${FZF_DEFAULT_OPTS-} ${FZF_ALT_C_OPTS-} +m" dir=$( FZF_DEFAULT_COMMAND=${FZF_ALT_C_COMMAND:-} FZF_DEFAULT_OPTS="$opts" $(__fzfcmd) ) && printf 'builtin cd -- %q' "$dir"}
if command -v perl > /dev/null; then __fzf_history__() {80 unmodified linesmodified:shell/key-bindings.fish+6 added-15 removed
23 unmodified lines24 set -l dir $commandline[1]25 set -l fzf_query $commandline[2]26 set -l prefix $commandline[3]27 28- # "-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@^\./@@'"35-28 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 return36 unmodified lines73 set -l dir $commandline[1]74 set -l fzf_query $commandline[2]75 set -l prefix $commandline[3]76 84- 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 result82 83 if [ -n "$result" ]84 cd -- $result85 81 unmodified linesmodified:shell/key-bindings.zsh+2 added-8 removed
39 unmodified lines40 {41 42 # 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 echo17 unmodified lines68 bindkey -M viins '^T' fzf-file-widget69 70 # ALT-C - cd into the selected directory71 fzf-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 fi40 unmodified linesmodified:src/core.go+2 added-2 removed
115 unmodified lines116 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 }122 123 // Matcher124 forward := true39 unmodified lines164 }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 linesmodified:src/options.go+65 added
122 unmodified lines123 --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 exit126 127+ 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)132+133 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 from142 unmodified lines279 func firstLine(s string) string {280 return strings.SplitN(s, "\n", 2)[0]281 }282 283+type walkerOpts struct {284+ file bool285+ dir bool286+ hidden bool287+ follow bool288+}289+290 // Options stores the values of command-line options291 type Options struct {292 Fuzzy bool293 FuzzyAlgo algo.Algo60 unmodified lines354 Tabstop int355 ListenAddr *listenAddress356 Unsafe bool357 ClearOnExit bool358+ WalkerOpts walkerOpts359+ WalkerRoot string360+ WalkerSkip []string361 Version bool362 }363 364+func 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+}373+374 func 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 lines438 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 }447 448 func help(code int) {545 unmodified lines994 }995 return theme996 }997 998+func 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+}1021+1022 var (1023 executeRegexp *regexp.Regexp1024 splitRegexp *regexp.Regexp1025 actionNameRegexp *regexp.Regexp906 unmodified lines1932 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 // Ignored89 unmodified lines2035 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 linesmodified:src/reader.go+16 added-8 removed
91 unmodified lines92 r.fin(success)93 }94 95 // ReadSource reads data from the default command or from standard input96-func (r *Reader) ReadSource() {96+func (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 lines144 r.feed(os.Stdin)145 return true146 }147 148-func (r *Reader) readFiles() bool {148+func (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 lines176 return context.Canceled177 }178 return nil179 }172- return fastwalk.Walk(&conf, ".", fn) == nil180+ return fastwalk.Walk(&conf, root, fn) == nil181 }182 183 func (r *Reader) readFromCommand(command string, environ []string) bool {184 r.mutex.Lock()19 unmodified linesmodified:CHANGELOG.md+34 added-4 removed
1 CHANGELOG2 =========3 4+0.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_COMMAND16+17+ fzf # default: --walker=file,follow,hidden --walker-root=. --walker-skip=.git,node_modules18+ fzf --walker=file,dir,hidden,follow --walker-skip=.git,node_modules,target19+20+ # Walker options in $FZF_DEFAULT_OPTS21+ export FZF_DEFAULT_OPTS="--walker=file,dir,hidden,follow --walker-skip=.git,node_modules,target"22+ fzf23+24+ # Reading from STDIN; --walker is ignored25+ seq 100 | fzf --walker=dir26+27+ # 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.32+33 0.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 lines51 52 [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_philosophy56 57 0.46.158 ------59 - Bug fixes and improvements1861 unmodified linesmodified:README.md+15 added-5 removed
229 unmodified lines230 find * -type f | fzf > selected231 ```232 233 Without STDIN pipe, fzf will traverse the file system under the current234-directory to get the list of files, skipping hidden directories. (You can235-override the default behavior with `FZF_DEFAULT_COMMAND`)234+directory to get the list of files.235 236 ```sh237 vim $(fzf)238 ```239 240+> 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`243+244 > *: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 vim142 unmodified lines390 The install script will setup the following key bindings for bash, zsh, and391 fish.392 393 - `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-line10 unmodified lines416 --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 ```430 431 If you're on a tmux session, you can start fzf in a tmux split-pane or in432 a tmux popup window by setting `FZF_TMUX_OPTS` (e.g. `export FZF_TMUX_OPTS='-p80%,60%'`).363 unmodified lines796 797 # Setting fd as the default source for fzf798 export FZF_DEFAULT_COMMAND='fd --type f --strip-cwd-prefix'799 790-# Now fzf (w/o pipe) will use fd instead of find800+# Now fzf (w/o pipe) will use the fd command to generate the list801 fzf802 803 # To apply the command to CTRL-T as well804 export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND"46 unmodified lines