Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I’ve never used fzf before and live in a shell all day, but the capabilities shown in the article doesn’t seem very useful to me. Am I missing something?

For Ctrl+R, how many times are people running similar variants of commands that they 1) don’t know what they typed and 2) didn’t think to simplify their workflow to not be running duplicated commands?

For Alt+C, are peoples’ file and directory layouts such a mess that they need to search entire directory trees to find what they’re looking for?

I’m confused.



For Ctrl+R, suppose you ran 'curl' against a bunch of API endpoints on a single domain name 2 months ago. I can now easily find one without knowing too much detail by fuzzy searching curl+part_of_domain_name+part_of_path.

For Alt+C, yes files and directories are often a huge mess. It may be no fault of your own. Maybe you're working with a giant legacy codebase or digging into node_modules. Now you can type 'vim Alt+C', to find and immediately open whatever you're looking for.

Of course this can all be done other ways, but it's very convenient and very fast when paired with ripgrep especially.


I usually do a `history | grep something | grep somethingelse` to find stuff in my history


Regarding Ctrl+R: Forget fzf for a moment and ask if you ever use it or some similar history command. If you do, then fzf is automatically a better interface than the default one.

If you don't, then yes, I use it all the time to find the exact command I typed in a few weeks ago. I'm not going to memorize all the options I passed in, etc.

For Alt+C: Useful even if you organize things very well. I'm in my home directory. I have /home/me/media/video/youtube/channel_name. I want to go in there. That's a lot of typing (even with Tab autocompletion). When I can just press Alt+C and type perhaps 4 characters of the channel name and I'm instantly in that directory. Do this 100 times over for different directories and the benefits become obvious. In the past I would put convenient symlinks to get to deeper directories quickly, and I now realize that approach is just a hack due to a poor navigation interface.


> For Alt+C, are peoples’ file and directory layouts such a mess that they need to search entire directory trees to find what they’re looking for?

Have you ever joined a new project? Usually they're both messy and you don't know where anything is.

Besides, even now with plenty of familiarity in my current legacy code base I can use fzf to type filenames or directories without typing the full path.

Ctrl+R is great for those repeat commands in your shell history that you want to use right now but don't want to add to your .bashrc, like repeatedly running a script with some arguments. I think the value of searching your history is self evident.


>Have you ever joined a new project?

Shouldn't your new team members work to help onboard you instead? Shouldn't you get ample training in your job?


You dropped your /s


Not often, and when that does happen a 'grep .histfile' seems more than adequate for finding these one off's.

Likewise, if you get your directory layout rationalized, good tab completion and disambiguation feels like all you would need.


it's simple: search can be a better interface than manual tagging and organizing


You're essentially asking why people ride bikes when they can just pop on shoes and walk instead.


I use Ctrl+R instead of hitting my up arrow key until I find a command I want to reuse.


fuzzy matching is honestly vastly superior to any sequential search, the few times where the match is incorrect still feels a better time investment as a user


I use Ctrl+R profusely. I don't like hitting up to cycle through recent commands.

Also sometimes I want to run something I haven't run in several days.


>Am I missing something?

Yes, the article misses what fzf actually is by focusing too much on the shell integrations. I hardly ever use those features, except for fzf-tab (which partially subsumes them).

Fundamentally, fzf is a well-behaved UNIX tool for choosing things. It does one thing well (choosing things), it communicates by simple text streams on stdin and stdout, and it integrates seamlessly with other text-based programs.

It's like an interactive, human-friendly version of grep that narrows down the possibilities on every keypress. You pass any newline-separated text to its stdin, and it will let you choose from among them. Whatever you choose will get written to stdout. This can be a single choice or multiple choices. You can customize the layout and even run arbitrary scripts when each option is selected (not chosen) to show a preview.

Once you recognize it, "choosing things" shows up everywhere, so fzf can accelerate any terminal-based workflow. Examples of what I use it for:

- what unit tests to run

- what git branch/commit to check out

- what process to kill

- what wifi to connect to

- what todo list items to check off

- find an emoji and put it on the clipboard

- you're leaving your laptop and you want to choose among shutdown/restart/suspend/logout/lockscreen

- what files or options to pass into an arbitrary command (using fzf-tab)

Basically anything that, if it were in a GUI, would be shown as radio buttons or checkboxes or a dropdown menu.

You can use it in scripts/aliases, or you can just write a quick fzf command inline. I use it for so many things, it's hard to even recall them. It's part of my muscle memory now. Check the wiki on the fzf github, there are all kinds of examples. e.g. here's the one I use for killing processes[2].

An example from recently where I used it "inline": I was in the middle of debugging something in a Python project. I needed to temporarily remove a bunch of packages from the virtual envirnoment, but not all of them, to narrow down where the problem was coming from. After 20 seconds of trial and error (I forgot the syntax for tail) I had:

    pip uninstall $(pip list | tail -n+3 | cut -d' ' -f1 | fzf -m)
This let me multi-select from the list of installed packages and uninstall them. Go down the list, boom-boom-boom, done. Pressing enter would uninstall my choices right away. Pressing tab would first expand the $() and replace it with the stdout of the pipeline inside, so the text after the prompt would become `pip uninstall requests numpy pandas ...` or whatever I chose, without running the `pip uninstall` part until I pressed enter. I tend to do the tab-expand trick a lot with multi-selections or with dangerous commands like rm, so I can double-check the full thing first before running it.

NB: in that pip example, the "fuzzy" part wasn't even relevant. All I did was use the up- and down- arrows to navigate the list .. there were only a few dozen entries so I didn't need the fuzzy-search. In fact, in most of my scripts I actually turn off the fuzzy matching and use the --exact flag, so that it just searches for exact substrings, whitespace-separated, order ignored. I find this makes its behaviour more predictable. e.g. if I want to find a pyproject.toml file from among all my files, in --exact mode I can just type "pypro" and it will show like

    ~/repos/foo/pyproject.toml
    ~/repos/bar/pyproject.toml
    ~/old-stuff/scripts/pyproject.toml
    ...
then I type "bar" to narrow it to the one in the "bar" repository, so my query is just "pypro bar". But unlike fuzzy mode, it doesn't show entries that just happen to have "b", "a", and "r" somewhere in the string, like something named

    ~/repos/big-archives/pyproject.toml
            ^   ^^
I have to type slightly more than I would with fuzzy-mode, but the lack of bad search results more than makes up for it.

This is what I mean when I say the core of fzf is "choosing things". It's not really about fuzzy-searching, despite the name.

[1] https://github.com/lincheney/fzf-tab-completion

[2] https://github.com/junegunn/fzf/wiki/Examples#processes




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: