Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add arguments to disable loading keybindings or completion #3722

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,28 @@ func main() {
protector.Protect()
options := fzf.ParseOptions()
if options.Bash {
printScript("key-bindings.bash", bashKeyBindings)
printScript("completion.bash", bashCompletion)
if options.KeyBindings {
printScript("key-bindings.bash", bashKeyBindings)
}
if options.Completion {
printScript("completion.bash", bashCompletion)
}
return
}
if options.Zsh {
printScript("key-bindings.zsh", zshKeyBindings)
printScript("completion.zsh", zshCompletion)
if options.KeyBindings {
printScript("key-bindings.zsh", zshKeyBindings)
}
if options.Completion {
printScript("completion.zsh", zshCompletion)
}
return
}
if options.Fish {
printScript("key-bindings.fish", fishKeyBindings)
fmt.Println("fzf_key_bindings")
if options.KeyBindings {
printScript("key-bindings.fish", fishKeyBindings)
fmt.Println("fzf_key_bindings")
}
return
}
fzf.Run(options, version, revision)
Expand Down
16 changes: 16 additions & 0 deletions src/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ const usage = `usage: fzf [options]
(default: .git,node_modules)

Shell integration
--no-completion Do not print the shell integration for completion
--no-key-bindings Do not print the shell integration for key bindings
--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
Expand Down Expand Up @@ -290,6 +292,8 @@ type walkerOpts struct {

// Options stores the values of command-line options
type Options struct {
Completion bool
KeyBindings bool
Bash bool
Zsh bool
Fish bool
Expand Down Expand Up @@ -381,6 +385,8 @@ func defaultPreviewOpts(command string) previewOpts {

func defaultOptions() *Options {
return &Options{
Completion: true,
KeyBindings: true,
Bash: false,
Zsh: false,
Fish: false,
Expand Down Expand Up @@ -1677,6 +1683,16 @@ func parseOptions(opts *Options, allArgs []string) {
for i := 0; i < len(allArgs); i++ {
arg := allArgs[i]
switch arg {
case "--no-completion":
opts.Completion = false
if !opts.KeyBindings {
errorExit("cannot specify --no-completion and --no-key-bindings")
}
case "--no-key-bindings":
opts.KeyBindings = false
if !opts.Completion {
errorExit("cannot specify --no-completion and --no-key-bindings")
}
case "--bash":
opts.Bash = true
if opts.Zsh || opts.Fish {
Expand Down