Live data from Hacker News

So you've installed `fzf` – now what?

andrew-quinn.me

251–260 of 292 posts

Re: So you've installed `fzf` – now what?

#251

Earlier quoted context omitted.

I often have three or more terminals open, doing different tasks in each; I also often have cycles of work where I'll repeat the last three commands again (three up-arrows and a return). This breaks if one terminal's commands get inserted into another terminal's history.

My solution is I immediately record the commands, but do not load them. That way new terminals get all the history, but old terminals keep their flow.

But if you go back later, the chains of commands from different terminals are interlaced right?

Re: So you've installed `fzf` – now what?

#252
post #50

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 th…

>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

Re: So you've installed `fzf` – now what?

#253
OP here, thank you all for your kind and insightful comments. There are a lot of very talented fzf users here!

I wrote this post following diataxis.fr's advice on writing tutorials:

>A tutorial must help a beginner achieve basic competence with a product, so that they can go on to use the product for their own purposes.

>A tutorial also needs to show the learner that they can be successful with the product - by having them do something both meaningful and attainable.

I think I have succeeded on that front judging by the reaction. :)

https://diataxis.fr/tutorials/

Re: So you've installed `fzf` – now what?

#254
Personally i never like the "interactive" part of fzf, ideally i should be able to do micro | fzf "myfile" and have it opened in the editor (fzf matching the first result for the file name)

Instead it's :

micro $(fzf) , then type the filename , select it and presee enter to get it opened in the editor.

Re: So you've installed `fzf` – now what?

#255
post #208
post #57

Earlier quoted context omitted.

I wanted to like atuin. The idea is great. But it just could not match the instant search that ctrl-r with fzf offers sadly. There is always a noticeable delay that annoyed me and made me revert back to fzf for search. For me another issue was that I needed to do more keystrokes for the same behaviour (search a previously ran command and execute it). Fuzzy shell history search is just one of those mind-blowing things…

Same, I enjoyed atuin but found myself missing fzf's fuzzy search experience so I ported fzf's own ctrl-r zsh widget to read from atuin instead of the shell's history to solve this. Best of both worlds imo, you get fzf's fuzzy search experience and speed with atuin's shell history management and syncing functionality. Zsh snippet below in case it's helpful to anybody. With this in your .zshrc ctrl-r will search your…

Thanks, just needed to set `CUR_SHELL=zsh` to make it work. Also `brew install atuin fzf`

Re: So you've installed `fzf` – now what?

#257
post #256

Is it just me or is it mildly annoying that I need to press enter twice if I Ctrl-R with fzf, as opposed to once with the regular search?

I just checked this, I thought you got it wrong, but you are indeed right :D I was never annoyed by this, I see the first enter as to confirm the "search results", and then another to to actually execute the command.

Re: So you've installed `fzf` – now what?

#258
post #213

The article is a pretty helpful collection of examples, and I appreciate it. The intro irks me, though: > Software engineers are, if not unique, then darn near unique in the ease with which we can create tools to improve our own professional lives; this however can come at a steep cost over time for people who constantly flit back and forth between different tools without investing the time to learn their own kit in…

A woodworker needs a supply of dry wood and can't just TDD, or undo/redo their way to a table. Ditto for other fields.

A woodworker will also just try stuff. They will also first lay out some specs and then start out to fill those specs. One step a time.

While not TDD by the letter, many crafts work more or less agile, and more or less incremental.

An example: I'm currently cutting down some 15 trees (Elms, died of Elm Blight). While it's impossible to cut down a single tree using TDD, I do cut them down incrementally, agile and in small steps: start out with the smallest tree (that stands alone) see how it reacts. Don't plan too far ahead, but plan a little - escape route, sharpen the chains etc. TDD wise: delivery criteria is "wood on a safe, manageable pile".

(I halted the moment a funny little owl peeked out of one of the trees, annoyed. Apparently it was building a nest and I'm too late in the season. Also agile)

Re: So you've installed `fzf` – now what?

#259

I love fuzzy shell history. Game changer in terms of shell productivity. I use atuin[0] instead of fzf as I find the experience a bit nicer and it has history backups built in (disclaimer, I am a maintainer) Some of our users still prefer fzf because they are used to how it fuzzy finds, but we're running an experiment with skim[1] which allows us to embed the fuzzy engine without much overhead - hopefully giving them…

FYI, speaking as a skim library user/lover, two things -- 1) it's really not maintained, and 2) once you dig into the code it gets a little gnarly. I have a branch[0] where I'm trying to do things like reduce the user perceptible lag in search, the initial time of ingest, and add small features I need, etc (all done). I've tried to create PRs where I can, and they go unnoticed and unused. One other thing I was trying…

> it's really not maintained

What do you mean by maintained? There are commits as recent as yesterday on the project: https://github.com/junegunn/fzf

Post reply on HN