From 88f4c16755d8fb53e55adec84d60d4aeaf1e7d91 Mon Sep 17 00:00:00 2001 From: Eli Barzilay Date: Sun, 17 Mar 2024 03:06:48 -0400 Subject: [PATCH] Make it possible to disable `Ctrl+T` / `Alt+C` / completions (#3678) This makes it possible to skip one of the above key bindings or completions by setting a variable to an empty string. For example, FZF_CTRL_T_COMMAND= FZF_ALT_C_COMMAND= \ eval "$(fzf --zsh)" Co-authored-by: Junegunn Choi --- CHANGELOG.md | 16 ++++++++++++++++ README.md | 4 ++++ shell/key-bindings.bash | 24 +++++++++++++++--------- shell/key-bindings.fish | 16 ++++++++++++---- shell/key-bindings.zsh | 20 ++++++++++++-------- test/test_go.rb | 3 +-- 6 files changed, 60 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f902833e..fc312d79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,22 @@ CHANGELOG ========= +0.48.1 +------ +- CTRL-T and ALT-C bindings can be disabled by setting `FZF_CTRL_T_COMMAND` and `FZF_ALT_C_COMMAND` to empty strings respectively when sourcing the script + ```sh + # bash + FZF_CTRL_T_COMMAND= FZF_ALT_C_COMMAND= eval "$(fzf --bash)" + + # zsh + FZF_CTRL_T_COMMAND= FZF_ALT_C_COMMAND= eval "$(fzf --zsh)" + + # fish + fzf --fish | FZF_CTRL_T_COMMAND= FZF_ALT_C_COMMAND= source + ``` + - Setting the variables after sourcing the script will have no effect +- Bug fixes + 0.48.0 ------ - Shell integration scripts are now embedded in the fzf binary. This simplifies the distribution, and the users are less likely to have problems caused by using incompatible scripts and binaries. diff --git a/README.md b/README.md index 4b8867a0..909b5276 100644 --- a/README.md +++ b/README.md @@ -437,6 +437,8 @@ fish. --preview 'bat -n --color=always {}' --bind 'ctrl-/:change-preview-window(down|hidden|)'" ``` + - Can be disabled by setting `FZF_CTRL_T_COMMAND` to an empty string when + sourcing the script - `CTRL-R` - Paste the selected command from history onto the command-line - If you want to see the commands in chronological order, press `CTRL-R` again which toggles sorting by relevance @@ -462,6 +464,8 @@ fish. --walker-skip .git,node_modules,target --preview 'tree -C {}'" ``` + - Can be disabled by setting `FZF_ALT_C_COMMAND` to an empty string when + sourcing the script If you're on a tmux session, you can start fzf in a tmux split-pane or in a tmux popup window by setting `FZF_TMUX_OPTS` (e.g. `export FZF_TMUX_OPTS='-p80%,60%'`). diff --git a/shell/key-bindings.bash b/shell/key-bindings.bash index f6cd48f1..a290e4ca 100644 --- a/shell/key-bindings.bash +++ b/shell/key-bindings.bash @@ -102,9 +102,11 @@ bind -m emacs-standard '"\C-z": vi-editing-mode' if (( BASH_VERSINFO[0] < 4 )); then # CTRL-T - Paste the selected file path into the command line - bind -m emacs-standard '"\C-t": " \C-b\C-k \C-u`__fzf_select__`\e\C-e\er\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f"' - bind -m vi-command '"\C-t": "\C-z\C-t\C-z"' - bind -m vi-insert '"\C-t": "\C-z\C-t\C-z"' + if [[ "${FZF_CTRL_T_COMMAND-x}" != "" ]]; then + bind -m emacs-standard '"\C-t": " \C-b\C-k \C-u`__fzf_select__`\e\C-e\er\C-a\C-y\C-h\C-e\e \C-y\ey\C-x\C-x\C-f"' + bind -m vi-command '"\C-t": "\C-z\C-t\C-z"' + bind -m vi-insert '"\C-t": "\C-z\C-t\C-z"' + fi # CTRL-R - Paste the selected command from history into the command line bind -m emacs-standard '"\C-r": "\C-e \C-u\C-y\ey\C-u`__fzf_history__`\e\C-e\er"' @@ -112,9 +114,11 @@ if (( BASH_VERSINFO[0] < 4 )); then bind -m vi-insert '"\C-r": "\C-z\C-r\C-z"' else # CTRL-T - Paste the selected file path into the command line - bind -m emacs-standard -x '"\C-t": fzf-file-widget' - bind -m vi-command -x '"\C-t": fzf-file-widget' - bind -m vi-insert -x '"\C-t": fzf-file-widget' + if [[ "${FZF_CTRL_T_COMMAND-x}" != "" ]]; then + bind -m emacs-standard -x '"\C-t": fzf-file-widget' + bind -m vi-command -x '"\C-t": fzf-file-widget' + bind -m vi-insert -x '"\C-t": fzf-file-widget' + fi # CTRL-R - Paste the selected command from history into the command line bind -m emacs-standard -x '"\C-r": __fzf_history__' @@ -123,6 +127,8 @@ else fi # ALT-C - cd into the selected directory -bind -m emacs-standard '"\ec": " \C-b\C-k \C-u`__fzf_cd__`\e\C-e\er\C-m\C-y\C-h\e \C-y\ey\C-x\C-x\C-d"' -bind -m vi-command '"\ec": "\C-z\ec\C-z"' -bind -m vi-insert '"\ec": "\C-z\ec\C-z"' +if [[ "${FZF_ALT_C_COMMAND-x}" != "" ]]; then + bind -m emacs-standard '"\ec": " \C-b\C-k \C-u`__fzf_cd__`\e\C-e\er\C-m\C-y\C-h\e \C-y\ey\C-x\C-x\C-d"' + bind -m vi-command '"\ec": "\C-z\ec\C-z"' + bind -m vi-insert '"\ec": "\C-z\ec\C-z"' +fi diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish index 51ddcc0d..6e62c59c 100644 --- a/shell/key-bindings.fish +++ b/shell/key-bindings.fish @@ -104,14 +104,22 @@ function fzf_key_bindings end end - bind \ct fzf-file-widget bind \cr fzf-history-widget - bind \ec fzf-cd-widget + if not set -q FZF_CTRL_T_COMMAND; or test -n "$FZF_CTRL_T_COMMAND" + bind \ct fzf-file-widget + end + if not set -q FZF_ALT_C_COMMAND; or test -n "$FZF_ALT_C_COMMAND" + bind \ec fzf-cd-widget + end if bind -M insert > /dev/null 2>&1 - bind -M insert \ct fzf-file-widget bind -M insert \cr fzf-history-widget - bind -M insert \ec fzf-cd-widget + if not set -q FZF_CTRL_T_COMMAND; or test -n "$FZF_CTRL_T_COMMAND" + bind -M insert \ct fzf-file-widget + end + if not set -q FZF_ALT_C_COMMAND; or test -n "$FZF_ALT_C_COMMAND" + bind -M insert \ec fzf-cd-widget + end end function __fzf_parse_commandline -d 'Parse the current command line token and return split of existing filepath, fzf query, and optional -option= prefix' diff --git a/shell/key-bindings.zsh b/shell/key-bindings.zsh index a3699add..51aa6ea0 100644 --- a/shell/key-bindings.zsh +++ b/shell/key-bindings.zsh @@ -62,10 +62,12 @@ fzf-file-widget() { zle reset-prompt return $ret } -zle -N fzf-file-widget -bindkey -M emacs '^T' fzf-file-widget -bindkey -M vicmd '^T' fzf-file-widget -bindkey -M viins '^T' fzf-file-widget +if [[ "${FZF_CTRL_T_COMMAND-x}" != "" ]]; then + zle -N fzf-file-widget + bindkey -M emacs '^T' fzf-file-widget + bindkey -M vicmd '^T' fzf-file-widget + bindkey -M viins '^T' fzf-file-widget +fi # ALT-C - cd into the selected directory fzf-cd-widget() { @@ -83,10 +85,12 @@ fzf-cd-widget() { zle reset-prompt return $ret } -zle -N fzf-cd-widget -bindkey -M emacs '\ec' fzf-cd-widget -bindkey -M vicmd '\ec' fzf-cd-widget -bindkey -M viins '\ec' fzf-cd-widget +if [[ "${FZF_ALT_C_COMMAND-x}" != "" ]]; then + zle -N fzf-cd-widget + bindkey -M emacs '\ec' fzf-cd-widget + bindkey -M vicmd '\ec' fzf-cd-widget + bindkey -M viins '\ec' fzf-cd-widget +fi # CTRL-R - Paste the selected command from history into the command line fzf-history-widget() { diff --git a/test/test_go.rb b/test/test_go.rb index 599d5442..97061de0 100755 --- a/test/test_go.rb +++ b/test/test_go.rb @@ -18,7 +18,6 @@ UNSETS = %w[ FZF_ALT_C_COMMAND FZF_ALT_C_OPTS FZF_CTRL_R_OPTS FZF_API_KEY - fish_history ].freeze DEFAULT_TIMEOUT = 10 @@ -67,7 +66,7 @@ class Shell end def fish - UNSETS.map { |v| v + '= ' }.join + ' FZF_DEFAULT_OPTS=--no-scrollbar fish' + "unset #{UNSETS.join(' ')}; FZF_DEFAULT_OPTS=--no-scrollbar fish_history= fish" end end end