9

I found a utility called fzf https://github.com/junegunn/fzf which is a fuzzy-finder for your shell.

Two questions:

1) After I run fzf and run a file, I press Enter and then the file I found is output in Terminal. Instead of Enter, what key should I press to copy that file path to my pastebin?

2) Ideally, I'd like to be able to do something like this: cat <pattern><hotkey> where I type part of the name of a file and then press a hotkey to start an fzf search for that pattern. Is there a way to do this?

2
  • you write "to my pastebin?" You mean to your clipboard
    – barlop
    Jun 6 '19 at 18:16
  • 1
    I meant to say "pasteboard" as described in man pbpaste
    – mark
    Jun 7 '19 at 2:06
8

I suggest that you read through the README page. You need a basic level of understanding of shell scripting in order to fully utilize fzf.

fzf is a Unix filter just like grep or sed, and all it does is to print the selected items. What to do with the output is completely up to you.


1) After I run fzf and run a file, I press Enter and then the file I found is output in Terminal. Instead of Enter, what key should I press to copy that file path to my pastebin?

You can use pbcopy command to store the result in clipboard like so:

fzf | pbcopy

More conventional way to use fzf is to use it with command substitution:

cat $(fzf)

Or to use the CTRL-T key binding that pastes the names of the selected files onto the command line:

cat <CTRL-T>

2) Ideally, I'd like to be able to do something like this: cat where I type part of the name of a file and then press a hotkey to start an fzf search for that pattern. Is there a way to do this?

fzf is shipped with fuzzy-completion for bash. See here for more details. To invoke auto-completion, append two asterisks to the pattern and hit the tab key as follows:

cat pat**<Tab>

If you don't use bash, the closest you can do is to use CTRL-T keybinding mentioned above.

See: https://github.com/junegunn/fzf#key-bindings-for-command-line

3
  • 1
    Ah, I found out my problem. I installed fzf via homebrew (brew install fzf), and the CTRL-T and pat**<Tab> shortcuts didn't work. I now installed fzf directly from the GitHub repo, and everything works now.
    – mark
    Sep 27 '14 at 20:52
  • 7
    brew install fzf will only install fzf executable. In order to install extra features, you have to run the attached install script after the installation. See brew info fzf for more info. Sep 28 '14 at 1:36
  • @JunegunnChoi yeah that's mentioned aheil.de/2019/04/07/fzf-command-line-fuzzy-finder-on-macos-x
    – barlop
    Jun 6 '19 at 18:17
2

I tried installing fzf via homebrew and my CTRL-T and pat** shortcuts also did not work. I found that fzf added some commands to my .bashrc, but my .bashrc doesn't get called.

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

Putting that same source statement from .bashrc into .bash_aliases did the trick for me.

1
  • .bash_profile for me.. 'cos apparently osx doesn't use .bashrc it uses .bash_profile
    – barlop
    Jun 6 '19 at 18:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.