-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Checklist
- I have read through the manual page (
man fzf) - I have searched through the existing issues
- For bug reports, I have checked if the bug is reproducible in the latest version of fzf
Output of fzf --version
0.67.0 (2ab923f)
OS
- Linux
- macOS
- Windows
- Etc.
Shell
- bash
- zsh
- fish
Problem / Steps to reproduce
Problem: Undocumented override of readline ALT-R keybinding
Readline man page shows revert-line has a default binding of ALT-R. As of v0.67.0, the __fzf_cd__ function overrides this default readline binding to redraw-current-line on line 124 (bind -m emacs-standard '"\er": redraw-current-line') of key-bindings.bash.
FZF Custom ALT-R readline keybinding
Unlike the ALT-C integration of FZF, the ALT-R ("\er") readline keybinding is not explicitly exposed to the user in any FZF documentation and is used in FZF internal macros only:
If statement block for BASH version < 4:
Line 133 (non-empty FZF_CTRL_T_COMMAND-x if statement):
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\e y\C-x\C-x\C-f\C-y\ey\C-_"'
Line 143 (non-empty FZF_CTRL_R_COMMAND-x if statement):
bind -m emacs-standard '"\C-r": " \C-b\C-k \C-u`__fzf_select__`\e\C-e\er\C-a\C-y\C-h\C-e\e \C-y\e y\C-x\C-x\C-f\C-y\ey\C-_"'
If statement block for non-empty FZF_ALT_C_COMMAND-x:
Line 168:
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\C-y\ey\C-_"'
Effects of attempting to restore revert-line keybinding in ~/.inputrc
Without explicit knowledge of this readline key binding override, a user who manually sets this ALT-R key binding in ~/.inputrc back to revert-line changes the FZF ALT_C behavior to add an empty readline complete command after the builtin cd to the selected directory, listing all binary executables in the user's $PATH.
# ~/.inputrc
"\er": revert-line
Suggestion
Given that the redraw-current-line readline command is used exclusively in internal FZF macros, any arbitrary keybinding not assigned by default or elsewhere will work without directly impacting FZF users (aside from those who have a custom keybinding already assigned to the arbitrary keybinding in __fzf_cd__).
I recommend using a capital R keybinding (as in SHIFT-ALT-R) for the redraw-current-line readline command, substituting \er with \eR in lines 124, 133, 143 and 168 of the v0.67.0 key-bindings.bash as follows:
Line 124:
# /shell/key-bindings.bash (copied to /usr/share/fzf/key-bindings.bash)
bind -m emacs-standard '"\eR": redraw-current-line'
Line 133:
# /shell/key-bindings.bash (copied to /usr/share/fzf/key-bindings.bash)
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\e y\C-x\C-x\C-f\C-y\ey\C-_"'
Line 143:
# /shell/key-bindings.bash (copied to /usr/share/fzf/key-bindings.bash)
bind -m emacs-standard '"\C-r": " \C-b\C-k \C-u`__fzf_select__`\e\C-e\eR\C-a\C-y\C-h\C-e\e \C-y\e y\C-x\C-x\C-f\C-y\ey\C-_"'
Line 168:
# /shell/key-bindings.bash (copied to /usr/share/fzf/key-bindings.bash)
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\C-y\ey\C-_"'
ZSH
The key-bindings.zsh file does not contain the redraw-current-line readline command as a custom keybind (which makes sense), so no impact on ZSH users is expected.
Reference
Man page style unfortunately shows the Emacs meta binding as "M-R", implying a ALT-SHIFT-R key sequence, but it is in fact lowercase "r" as shown in the revert-line command description:
revert-line (M-r)
Undo all changes made to this line. This is like executing the undo command enough times
to return the line to its initial state.
I also manually confirmed SHIFT-ALT-R does not call the revert-line command in emacs mode.
Review of other issues
I reviewed the following issues to see if this issue has been raised/responded to previously:
- key-bindings fail if user used keyseqs have non-default assignments #3461
- Can't bind C-z to a readline function without getting 'readline: maximum macro execution nesting level exceeded' with fzf-cd - Alt-C #3838
- Adding support for more readline keybindings : Support for Alt+Minus Control+k #2660
- Bash: Key bindings fixes #489