Skip to content
Myr

Add $FZF_DEFAULT_OPTS_FILE (#3618)

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

For those who prefer to manage default options in a file. If the file is not found, fzf will exit with an error. We're not setting a default value for it because: 1. it's hard to find a default value that can be universally agreed upon 2. to avoid fzf having to check for the existence of the file even when it's not used

authored by Junegunn Choi · committed by GitHub · parent 3dd42f5 · Browse files · 5 files+50 added−7 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+50 added−7 removed

  • tests:+1 added−0 removed
  • other:+49 added−7 removed

5 files+50 added−7 removed

modified:man/man1/fzf.1+8 added-1 removed
863 unmodified lines
864with \fB$SHELL -c\fR if \fBSHELL\fR is set, otherwise with \fBsh -c\fR, so in865this case make sure that the command is POSIX-compliant.866.TP867.B FZF_DEFAULT_OPTS868Default options. e.g. \fBexport FZF_DEFAULT_OPTS="--extended --cycle"\fR868Default options.869.br870e.g. \fBexport FZF_DEFAULT_OPTS="--layout=reverse --border --cycle"\fR871.TP872.B FZF_DEFAULT_OPTS_FILE873The location of the file that contains the default options.874.br875e.g. \fBexport FZF_DEFAULT_OPTS_FILE=~/.fzfrc\fR876.TP877.B FZF_API_KEY878Can be used to require an API key when using \fB--listen\fR option. If not set,879no authentication will be required by the server. You can set this value if880you need to protect against DNS rebinding and privilege escalation attacks.
592 unmodified lines
modified:src/options.go+31 added-6 removed
124 unmodified lines
125 --version Display version information and exit126127 Environment variables128 FZF_DEFAULT_COMMAND Default command to use when input is tty129 FZF_DEFAULT_OPTS Default options130 (e.g. '--layout=reverse --inline-info')129 FZF_DEFAULT_OPTS Default options (e.g. '--layout=reverse --info=inline')130 FZF_DEFAULT_OPTS_FILE Location of the file to read default options from131 FZF_API_KEY X-API-Key header for HTTP server (--listen)132133`134
285 unmodified lines
420 os.Stdout.WriteString(usage)421 os.Exit(code)422}423424var errorContext = ""425426func errorExit(msg string) {425 os.Stderr.WriteString(msg + "\n")427 os.Stderr.WriteString(errorContext + msg + "\n")428 os.Exit(exitError)429}430431func optString(arg string, prefixes ...string) (bool, string) {
1736 unmodified lines
2168 return opts2169 }2170 }21712170 // Options from Env var2171 words, _ := shellwords.Parse(os.Getenv("FZF_DEFAULT_OPTS"))2172 // 1. Options from $FZF_DEFAULT_OPTS_FILE2173 if path := os.Getenv("FZF_DEFAULT_OPTS_FILE"); path != "" {2174 bytes, err := os.ReadFile(path)2175 if err != nil {2176 errorContext = "$FZF_DEFAULT_OPTS_FILE: "2177 errorExit(err.Error())2178 }21792180 words, parseErr := shellwords.Parse(string(bytes))2181 if parseErr != nil {2182 errorContext = path + ": "2183 errorExit(parseErr.Error())2184 }2185 if len(words) > 0 {2186 parseOptions(opts, words)2187 }2188 }21892190 // 2. Options from $FZF_DEFAULT_OPTS string2191 words, parseErr := shellwords.Parse(os.Getenv("FZF_DEFAULT_OPTS"))2192 errorContext = "$FZF_DEFAULT_OPTS: "2193 if parseErr != nil {2194 errorExit(parseErr.Error())2195 }2196 if len(words) > 0 {2197 parseOptions(opts, words)2198 }21992176 // Options from command-line arguments2200 // 3. Options from command-line arguments2201 errorContext = ""2202 parseOptions(opts, os.Args[1:])22032204 postProcessOptions(opts)2205 return opts
1 unmodified line
modified:test/test_go.rb+1 added
2580 unmodified lines
25812582 def test_change_preview_window_rotate2583 tmux.send_keys "seq 100 | #{FZF} --preview-window left,border-none --preview 'echo hello' --bind '" \2584 "a:change-preview-window(right|down|up|hidden|)'", :Enter2585 tmux.until { |lines| assert(lines.any? { _1.include?('100/100') }) }2586 3.times do2587 tmux.until { |lines| lines[0].start_with?('hello') }2588 tmux.send_keys 'a'2589 tmux.until { |lines| lines[0].end_with?('hello') }
1041 unmodified lines
modified:CHANGELOG.md+6 added
10 unmodified lines
11 - 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.15- Added `$FZF_DEFAULT_OPTS_FILE` to allow managing default options in a file16 - See [#3618](https://github.com/junegunn/fzf/pull/3618)17 - Option precedence from lower to higher18 1. Options read from `$FZF_DEFAULT_OPTS_FILE`19 1. Options from `$FZF_DEFAULT_OPTS`20 1. Options from command-line arguments2122[find]: https://github.com/junegunn/fzf/blob/0.46.1/src/constants.go#L60-L6423[walker]: https://github.com/junegunn/fzf/pull/184724[fastwalk]: https://github.com/charlievieth/fastwalk
1865 unmodified lines
modified:README.md+4 added
327 unmodified lines
328 > The available options are described later in this document.329- `FZF_DEFAULT_OPTS`330 - Default options331 - e.g. `export FZF_DEFAULT_OPTS="--layout=reverse --inline-info"`332- `FZF_DEFAULT_OPTS_FILE`333 - If you prefer to manage default options in a file, set this variable to334 point to the location of the file335 - e.g. `export FZF_DEFAULT_OPTS_FILE=~/.fzfrc`336337### Options338339See the man page (`man fzf`) for the full list of options.
501 unmodified lines