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

[bash] Fire command directly with CTRL-X in CTRL-R #1492

Closed
wants to merge 1 commit into from

Conversation

4z3
Copy link

@4z3 4z3 commented Feb 5, 2019

This PR adds the ability to choose between direct execution and prior editing in CTRL-R for bash.

I'm not sure whether this implementation is acceptable as it is quite hacky and requires two dedicated readline bindings, but as demand for this feature seemed quite high, I've created a PR anyway =)

The trick used is to bind a command (to CTRL-O) that inspects the readline buffer and rebinds another binding (CTRL-P) to either accept a line or do nothing. The rebinding happens if the readline buffer contains a "magic suffix". __fzf_history__, in turn, adds the suffix based on the key used to make a selection. By default Enter allows the user to edit the selection, and CTRL-X will execute it immediately, i.e the same way it was proposed for zsh. As some users (me included) prefer to execute by default instead, the keys to choose between execution and editing have been made configurable, e.g.:

FZF_CTRL_R_EDIT_KEY=ctrl-e
FZF_CTRL_R_EXEC_KEY=enter

Related #477

@junegunn
Copy link
Owner

junegunn commented Feb 8, 2019

Thanks for your interest in the project.

Due to increasing maintenance burden, I decided not to add more options to the key bindings this repository provides. Ensuring consistent, stable user experience across three different shells – bash, zsh, and fish – turned out to be quite painful and has taken up much of my time.

So instead of having this merged to this repository, I suggest that you create a separate "plugin" with extended features and options, so that the users can optionally install your bindings if they want.

[ -f ~/.fzf.bash ] && source ~/.fzf.bash

# Load your plugin to override the bindings

@markmcd
Copy link

markmcd commented Feb 27, 2019

If you turned this into a plugin, I'd love to use it. Could you share a link here so other Google-searchers can find it?

4z3 added a commit to 4z3/fzf-plugins that referenced this pull request Feb 28, 2019
4z3 added a commit to 4z3/fzf-plugins that referenced this pull request Feb 28, 2019
4z3 added a commit to 4z3/fzf-plugins that referenced this pull request Feb 28, 2019
4z3 added a commit to 4z3/fzf-plugins that referenced this pull request Feb 28, 2019
@4z3
Copy link
Author

4z3 commented Feb 28, 2019

This PR's code has been copied to 4z3/fzf-plugins.

@nhooyr
Copy link
Contributor

nhooyr commented May 31, 2020

This was quite easy in zsh.

See https://github.com/nhooyr/dotfiles/blob/92623b7a3e9fa421d191f6c2bb77de4ce60aa367/zsh/fzf.zsh#L48-L61

@4z3 4z3 mentioned this pull request Jul 9, 2020
@junegunn junegunn mentioned this pull request Nov 26, 2020
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants