Make it possible to disable `Ctrl+T` / `Alt+C` / completions (#3678)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
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)"
authored by Eli Barzilay · committed by GitHub · parent c7ee071 · Browse files · 6 files·+60 added−23 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Trailers
- Co-authored-by: Junegunn Choi <junegunn.c@gmail.com>
Diff stats
6 files+60 added−23 removed
- tests:+1 added−2 removed
- other:+59 added−21 removed
Provenance
- Commit
88f4c16- Tree
2b33afc- Author
Eli Barzilay <eli@barzilay.org>- Committer
GitHub <noreply@github.com>- Parent
c7ee071
6 files changed+60 added−23 removed
modified:shell/key-bindings.bash+15 added-9 removed
100 unmodified lines101102103104105105106107106107108109110111112113114115116115116117117118119120121122123124125126127128129130126127128131132133134100 unmodified linesbind -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 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"' 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"' bind -m vi-command '"\C-r": "\C-z\C-r\C-z"' 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__' bind -m vi-command -x '"\C-r": __fzf_history__' bind -m vi-insert -x '"\C-r": __fzf_history__'fi
# ALT-C - cd into the selected directoryif [[ "${FZF_ALT_C_COMMAND-x}" != "" ]]; thenbind -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"' 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"'fimodified:shell/key-bindings.fish+12 added-4 removed
102 unmodified lines103 echo "fzf"104 end105 end106 107- bind \ct fzf-file-widget107 bind \cr fzf-history-widget108+ if not set -q FZF_CTRL_T_COMMAND; or test -n "$FZF_CTRL_T_COMMAND"109+ bind \ct fzf-file-widget110+ end111+ if not set -q FZF_ALT_C_COMMAND; or test -n "$FZF_ALT_C_COMMAND"109- bind \ec fzf-cd-widget112+ bind \ec fzf-cd-widget113+ end114 115 if bind -M insert > /dev/null 2>&1112- bind -M insert \ct fzf-file-widget116 bind -M insert \cr fzf-history-widget117+ if not set -q FZF_CTRL_T_COMMAND; or test -n "$FZF_CTRL_T_COMMAND"118+ bind -M insert \ct fzf-file-widget119+ end120+ if not set -q FZF_ALT_C_COMMAND; or test -n "$FZF_ALT_C_COMMAND"114- bind -M insert \ec fzf-cd-widget121+ bind -M insert \ec fzf-cd-widget122+ end123 end124 125 function __fzf_parse_commandline -d 'Parse the current command line token and return split of existing filepath, fzf query, and optional -option= prefix'126 set -l commandline (commandline -t)48 unmodified linesmodified:shell/key-bindings.zsh+12 added-8 removed
60 unmodified lines61 local ret=$?62 zle reset-prompt63 return $ret64 }65-zle -N fzf-file-widget66-bindkey -M emacs '^T' fzf-file-widget67-bindkey -M vicmd '^T' fzf-file-widget68-bindkey -M viins '^T' fzf-file-widget65+if [[ "${FZF_CTRL_T_COMMAND-x}" != "" ]]; then66+ zle -N fzf-file-widget67+ bindkey -M emacs '^T' fzf-file-widget68+ bindkey -M vicmd '^T' fzf-file-widget69+ bindkey -M viins '^T' fzf-file-widget70+fi71 72 # ALT-C - cd into the selected directory73 fzf-cd-widget() {74 setopt localoptions pipefail no_aliases 2> /dev/null9 unmodified lines84 unset dir # ensure this doesn't end up appearing in prompt expansion85 zle reset-prompt86 return $ret87 }86-zle -N fzf-cd-widget87-bindkey -M emacs '\ec' fzf-cd-widget88-bindkey -M vicmd '\ec' fzf-cd-widget89-bindkey -M viins '\ec' fzf-cd-widget88+if [[ "${FZF_ALT_C_COMMAND-x}" != "" ]]; then89+ zle -N fzf-cd-widget90+ bindkey -M emacs '\ec' fzf-cd-widget91+ bindkey -M vicmd '\ec' fzf-cd-widget92+ bindkey -M viins '\ec' fzf-cd-widget93+fi94 95 # CTRL-R - Paste the selected command from history into the command line96 fzf-history-widget() {97 local selected num24 unmodified linesmodified:test/test_go.rb+1 added-2 removed
16 unmodified lines17 FZF_CTRL_T_COMMAND FZF_CTRL_T_OPTS18 FZF_ALT_C_COMMAND19 FZF_ALT_C_OPTS FZF_CTRL_R_OPTS20 FZF_API_KEY21- fish_history21 ].freeze22 DEFAULT_TIMEOUT = 1023 24 FILE = File.expand_path(__FILE__)40 unmodified lines65 end66 end67 68 def fish70- UNSETS.map { |v| v + '= ' }.join + ' FZF_DEFAULT_OPTS=--no-scrollbar fish'69+ "unset #{UNSETS.join(' ')}; FZF_DEFAULT_OPTS=--no-scrollbar fish_history= fish"70 end71 end72 end73 3556 unmodified linesmodified:CHANGELOG.md+16 added
1 CHANGELOG2 =========3 4+0.48.15+------6+- 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 script7+ ```sh8+ # bash9+ FZF_CTRL_T_COMMAND= FZF_ALT_C_COMMAND= eval "$(fzf --bash)"10+11+ # zsh12+ FZF_CTRL_T_COMMAND= FZF_ALT_C_COMMAND= eval "$(fzf --zsh)"13+14+ # fish15+ fzf --fish | FZF_CTRL_T_COMMAND= FZF_ALT_C_COMMAND= source16+ ```17+ - Setting the variables after sourcing the script will have no effect18+- Bug fixes19+20 0.48.021 ------22 - 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.23 - bash1929 unmodified linesmodified:README.md+4 added
435 unmodified lines436 --walker-skip .git,node_modules,target437 --preview 'bat -n --color=always {}'438 --bind 'ctrl-/:change-preview-window(down|hidden|)'"439 ```440+ - Can be disabled by setting `FZF_CTRL_T_COMMAND` to an empty string when441+ sourcing the script442 - `CTRL-R` - Paste the selected command from history onto the command-line443 - If you want to see the commands in chronological order, press `CTRL-R`444 again which toggles sorting by relevance445 - Set `FZF_CTRL_R_OPTS` to pass additional options to fzf17 unmodified lines463 export FZF_ALT_C_OPTS="464 --walker-skip .git,node_modules,target465 --preview 'tree -C {}'"466 ```467+ - Can be disabled by setting `FZF_ALT_C_COMMAND` to an empty string when468+ sourcing the script469 470 If you're on a tmux session, you can start fzf in a tmux split-pane or in471 a tmux popup window by setting `FZF_TMUX_OPTS` (e.g. `export FZF_TMUX_OPTS='-p80%,60%'`).472 See `fzf-tmux --help` for available options.416 unmodified lines