2

fzf has some keybindings of which some are listed below as examples:

  • Alt+C: cd into the selected directory
  • Ctrl+T: select a file

I want to add a keybiding so that I can launch the selected file with fzf, maybe using xdg-open or mimeopen.

1 Answer 1

2

Add this to your .bashrc:

bind -x '"\C-o": file="$(fzf --height 40% --reverse)" && [ -f "$file" ] && xdg-open "$file"'

Restart your terminal, or run source .bashrc. Now you can use Ctrl+o to open files directly with preferred application.

2
  • Thanks. Why does this not need & to be run asynchronously?
    – 3N4N
    May 14, 2019 at 16:51
  • I added a history -s xdg-open "$file" before the actual command is run so that it's also added to history. Otherwise one misses out on history features, like using the up arrow to quickly re-run the last command---which is more efficient than using ctrl-o again.
    – FranciscoD
    Sep 8 at 9:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .