feat: Allow disabling Ctrl-R binding in shell integration (#4535)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Close #4417
authored by Jacobo de Vera · committed by GitHub · parent ab407c4 · Browse files · 5 files·+56 added−18 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+56 added−18 removed
- other:+56 added−18 removed
Provenance
- Commit
0e9026b- Tree
632a5c1- Author
Jacobo de Vera <devel@jacobodevera.com>- Committer
GitHub <noreply@github.com>- Parent
ab407c4
5 files changed+56 added−18 removed
modified:shell/key-bindings.bash+17 added-6 removed
5 unmodified lines67891011121314117 unmodified linesExpand all1321331341351361371381391351361371401411421431441451461471481491501511521531541551561471481491571581591601611621631647 unmodified lines5 unmodified lines## - $FZF_TMUX_OPTS# - $FZF_CTRL_T_COMMAND# - $FZF_CTRL_T_OPTS# - $FZF_CTRL_R_COMMAND# - $FZF_CTRL_R_OPTS# - $FZF_ALT_C_COMMAND# - $FZF_ALT_C_OPTS
117 unmodified linesExpand all 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 if [[ ${FZF_CTRL_R_COMMAND-x} != "" ]]; then if [[ -n ${FZF_CTRL_R_COMMAND-} ]]; then echo "warning: FZF_CTRL_R_COMMAND is set to a custom command, but custom commands are not yet supported for CTRL-R" >&2 fi bind -m emacs-standard '"\C-r": "\C-e \C-u\C-y\ey\C-u`__fzf_history__`\e\C-e\er"' bind -m vi-command '"\C-r": "\C-z\C-r\C-z"' bind -m vi-insert '"\C-r": "\C-z\C-r\C-z"' bind -m emacs-standard '"\C-r": "\C-e \C-u\C-y\ey\C-u`__fzf_history__`\e\C-e\er"' bind -m vi-command '"\C-r": "\C-z\C-r\C-z"' bind -m vi-insert '"\C-r": "\C-z\C-r\C-z"' fielse # CTRL-T - Paste the selected file path into the command line 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 if [[ ${FZF_CTRL_R_COMMAND-x} != "" ]]; then if [[ -n ${FZF_CTRL_R_COMMAND-} ]]; then echo "warning: FZF_CTRL_R_COMMAND is set to a custom command, but custom commands are not yet supported for CTRL-R" >&2 fi bind -m emacs-standard -x '"\C-r": __fzf_history__' bind -m vi-command -x '"\C-r": __fzf_history__' bind -m vi-insert -x '"\C-r": __fzf_history__' bind -m emacs-standard -x '"\C-r": __fzf_history__' bind -m vi-command -x '"\C-r": __fzf_history__' bind -m vi-insert -x '"\C-r": __fzf_history__' fifi
# ALT-C - cd into the selected directoryif [[ ${FZF_ALT_C_COMMAND-x} != "" ]]; then7 unmodified linesmodified:shell/key-bindings.fish+8 added-2 removed
5 unmodified lines6 #7 # - $FZF_TMUX_OPTS8 # - $FZF_CTRL_T_COMMAND9 # - $FZF_CTRL_T_OPTS10+# - $FZF_CTRL_R_COMMAND11 # - $FZF_CTRL_R_OPTS12 # - $FZF_ALT_C_COMMAND13 # - $FZF_ALT_C_OPTS14 199 unmodified lines214 215 commandline -f repaint216 end217 218+ if not set -q FZF_CTRL_R_COMMAND; or test -n "$FZF_CTRL_R_COMMAND"219+ if test -n "$FZF_CTRL_R_COMMAND"220+ echo "warning: FZF_CTRL_R_COMMAND is set to a custom command, but custom commands are not yet supported for CTRL-R" >&2221+ end217- bind \cr fzf-history-widget218- bind -M insert \cr fzf-history-widget222+ bind \cr fzf-history-widget223+ bind -M insert \cr fzf-history-widget224+ end225 226 if not set -q FZF_CTRL_T_COMMAND; or test -n "$FZF_CTRL_T_COMMAND"227 bind \ct fzf-file-widget228 bind -M insert \ct fzf-file-widget8 unmodified linesmodified:shell/key-bindings.zsh+10 added-4 removed
5 unmodified lines6 #7 # - $FZF_TMUX_OPTS8 # - $FZF_CTRL_T_COMMAND9 # - $FZF_CTRL_T_OPTS10+# - $FZF_CTRL_R_COMMAND11 # - $FZF_CTRL_R_OPTS12 # - $FZF_ALT_C_COMMAND13 # - $FZF_ALT_C_OPTS14 135 unmodified lines150 fi151 zle reset-prompt152 return $ret153 }154+if [[ ${FZF_CTRL_R_COMMAND-x} != "" ]]; then155+ if [[ -n ${FZF_CTRL_R_COMMAND-} ]]; then156+ echo "warning: FZF_CTRL_R_COMMAND is set to a custom command, but custom commands are not yet supported for CTRL-R" >&2157+ fi153-zle -N fzf-history-widget154-bindkey -M emacs '^R' fzf-history-widget155-bindkey -M vicmd '^R' fzf-history-widget156-bindkey -M viins '^R' fzf-history-widget158+ zle -N fzf-history-widget159+ bindkey -M emacs '^R' fzf-history-widget160+ bindkey -M vicmd '^R' fzf-history-widget161+ bindkey -M viins '^R' fzf-history-widget162 fi163+fi164 165 } always {166 eval $__fzf_key_bindings_options167 'unset' '__fzf_key_bindings_options'1 unmodified linemodified:CHANGELOG.md+12 added
25 unmodified lines26 | New | Env Var | `FZF_SOCK` | Path to the Unix domain socket fzf is listening on |27 | Enhancement | Key | `CTRL-N` | `down` -> `down-match` |28 | Enhancement | Key | `CTRL-P` | `up` -> `up-match` |29 | Enhancement | Shell | `CTRL-R` binding | Toggle raw mode with `ALT-R` |30+| Enhancement | Shell | `CTRL-R` binding | Opt-out with an empty `FZF_CTRL_R_COMMAND` |31 32 ### Introducing "raw" mode33 34 This version introduces a new "raw" mode (named so because it shows the list196 unmodified lines231 As described above, `$FZF_RAW` is now exported to child processes in raw mode,232 indicating whether the current item is a match (`1`) or not (`0`). It is not233 defined when not in raw mode.234 235+#### `$FZF_CTRL_R_COMMAND`236+237+You can opt-out `CTRL-R` binding from the shell integration by setting238+`FZF_CTRL_R_COMMAND` to an empty string. Setting it to any other value is not239+supported and will result in a warning.240+241+```sh242+# Disable the CTRL-R binding from the shell integration243+FZF_CTRL_R_COMMAND= eval "$(fzf --bash)"244+```245+246 ### Added key support for `--bind`247 248 Pull request #3996 added support for many additional keys for `--bind` option,249 such as `ctrl-backspace`.2832 unmodified linesmodified:README.md+9 added-6 removed
216 unmodified lines217 > Please refer to the package documentation for more information.218 > (e.g. `apt show fzf`)219 220 > [!TIP]221-> You can disable CTRL-T or ALT-C binding by setting `FZF_CTRL_T_COMMAND` or222-> `FZF_ALT_C_COMMAND` to an empty string when sourcing the script.223-> For example, to disable ALT-C binding:221+> You can disable CTRL-T, CTRL-R, or ALT-C bindings by setting the222+> corresponding `*_COMMAND` variable to an empty string when sourcing the223+> script. For example, to disable CTRL-R and ALT-C:224 >225-> * bash: `FZF_ALT_C_COMMAND= eval "$(fzf --bash)"`226-> * zsh: `FZF_ALT_C_COMMAND= source <(fzf --zsh)`227-> * fish: `fzf --fish | FZF_ALT_C_COMMAND= source`225+> * bash: `FZF_CTRL_R_COMMAND= FZF_ALT_C_COMMAND= eval "$(fzf --bash)"`226+> * zsh: `FZF_CTRL_R_COMMAND= FZF_ALT_C_COMMAND= source <(fzf --zsh)`227+> * fish: `fzf --fish | FZF_CTRL_R_COMMAND= FZF_ALT_C_COMMAND= source`228 >229 > Setting the variables after sourcing the script will have no effect.230 231 ### Vim/Neovim plugin301 unmodified lines533 --bind 'ctrl-y:execute-silent(echo -n {2..} | pbcopy)+abort'534 --color header:italic535 --header 'Press CTRL-Y to copy command into clipboard'"536 ```537+ - Can be disabled by setting `FZF_CTRL_R_COMMAND` to an empty string when538+ sourcing the script539+ - Custom override via a non-empty `FZF_CTRL_R_COMMAND` is not yet supported and will emit a warning540 - `ALT-C` - cd into the selected directory541 - The list is generated using `--walker dir,follow,hidden` option542 - Set `FZF_ALT_C_COMMAND` to override the default command543 - Or you can set `--walker-*` options in `FZF_ALT_C_OPTS`466 unmodified lines