zshoh-my-zshfzf

ZSH automatically run commands after selecting FZF result


I'm using ZSH and am trying to integrate FZF into my config. It all works fine now, the only thing bothering me is that after searching for the command I want to run in FZF (e.g. a file/directory name) and pressing <ENTER> to close FZF, I have to press <ENTER> again to run the command.

Is there a way to run the command automatically after selecting an FZF result?

EDIT: Thanks to @svlasov I now have this solution:

export FZF_COMPLETION_TRIGGER=""
setopt vi # Removes the default FZF '<TAB>' keybinding

fzf-and-run-widget() {
    fzf-completion
    zle accept-line
}
zle -N         fzf-and-run-widget
bindkey '^[^I' fzf-and-run-widget

Solution

  • Add to .zshrc:

    fzf-and-run-widget() {
      fzf-history-widget
      zle accept-line
    }
    zle     -N   fzf-and-run-widget
    bindkey '^R' fzf-and-run-widget