summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2024-03-13 23:59:34 +0900
committerGitHub <noreply@github.com>2024-03-13 23:59:34 +0900
commite74b1251c0f579335e03b3e7182cd7a9f88dbe37 (patch)
tree635d9bd3d4be38ca5623b8ce7241c2674c01b532 /src
parentd282a1649d7d953f028306f13d6616958f3fd1f3 (diff)
Embed shell integration scripts in fzf binary (`--bash` / `--zsh` / `--fish`) (#3675)
This simplifies the distribution, and the users are less likely to have problems caused by using incompatible scripts and binaries. # Set up fzf key bindings and fuzzy completion eval "$(fzf --bash)" # Set up fzf key bindings and fuzzy completion eval "$(fzf --zsh)" # Set up fzf key bindings fzf --fish | source
Diffstat (limited to 'src')
-rw-r--r--src/options.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/options.go b/src/options.go
index fdad058d..692ce6b2 100644
--- a/src/options.go
+++ b/src/options.go
@@ -130,6 +130,11 @@ const usage = `usage: fzf [options]
--walker-skip=DIRS Comma-separated list of directory names to skip
(default: .git,node_modules)
+ Shell integration
+ --bash Print script to set up Bash shell integration
+ --zsh Print script to set up Zsh shell integration
+ --fish Print script to set up Fish shell integration
+
Environment variables
FZF_DEFAULT_COMMAND Default command to use when input is tty
FZF_DEFAULT_OPTS Default options (e.g. '--layout=reverse --info=inline')
@@ -289,6 +294,9 @@ type walkerOpts struct {
// Options stores the values of command-line options
type Options struct {
+ Bash bool
+ Zsh bool
+ Fish bool
Fuzzy bool
FuzzyAlgo algo.Algo
Scheme string
@@ -377,6 +385,9 @@ func defaultPreviewOpts(command string) previewOpts {
func defaultOptions() *Options {
return &Options{
+ Bash: false,
+ Zsh: false,
+ Fish: false,
Fuzzy: true,
FuzzyAlgo: algo.FuzzyMatchV2,
Scheme: "default",
@@ -1655,6 +1666,21 @@ func parseOptions(opts *Options, allArgs []string) {
for i := 0; i < len(allArgs); i++ {
arg := allArgs[i]
switch arg {
+ case "--bash":
+ opts.Bash = true
+ if opts.Zsh || opts.Fish {
+ errorExit("cannot specify --bash with --zsh or --fish")
+ }
+ case "--zsh":
+ opts.Zsh = true
+ if opts.Bash || opts.Fish {
+ errorExit("cannot specify --zsh with --bash or --fish")
+ }
+ case "--fish":
+ opts.Fish = true
+ if opts.Bash || opts.Zsh {
+ errorExit("cannot specify --fish with --bash or --zsh")
+ }
case "-h", "--help":
help(exitOk)
case "-x", "--extended":