Fzf – a command-line fuzzy finder
github.com
github.com
It's incredible.
I use it 20-40 times an hour to do very fast Dev/DevOps development:
- "run Pytest when Python files change" - "I forgot how to use ps, run my-ps.sh when it changes and show me the output" - "rebuild all these Kubernetes resources when I edit the YAML files" - "run fast lint, then unit test Python files, then invoke one and show me the results"
There's another one that I've used that is written in go: https://github.com/cespare/reflex
I am inclined to use watchexec next time I need one, because like go, I can read it more easily than c, but also because I looked at the web page and GitHub repo and it seems worth trying. For instance, it shows how to use it as a library instead of just as a command-line tool. https://watchexec.github.io/
I can see how it could be helpful, but with the way I write software, that scares me. I save habitually, and not only when I'm actually ready to build the result.
This is called "debounce" in `watchexec` a similar program to `entr`
I think there’s something I don’t understand about GP:s workflow and needs.
This will run a binary when any file on the directory tree changes:
#!/usr/bin/env sh
set -e
while true; do
inotifywait -e modify,create,delete,move -r $1 $2
done
and then just call it: run_on_modify path/to/dir path/to/binIf someone thinks this is magic or wizardy, instead of teaching them that fire exists (entr), teach them how to make fire first (inotify, linux inodes, etc.). Knowing what kind of events inodes support and how to do something when they happen is pretty powerful.
If you then want to use "entr" or similar instead of just calling inotifywait yourself, that's fair game. But TBH I have a hard time justifying a C or Rust program that's not going to be available / installed everywhere when a 3 LOC POSIX shell script can solve the same problem (and many many more).
You can improve the basic loop somewhat, but a more thoroughly written program (whatever the language) rather than a 3 LOC loop is going to have more features and be more ergonomic. In particular, to truly be useful, it should be able to kill the command and restart it every time the file is saved.
I like them both for making fun zsh key bindings, so, so easy.
[0]: https://github.com/kimono-koans/httm [1]: https://github.com/lotabout/skim
But I suppose I'd ask -- faster how?
The linked benchmark really doesn't mean much to me. As an interactive app I judged it on how it felt latency-wise at the CLI. So, I would just try to scroll page-up while find was feeding in the files in my home directory. fzf would sometimes stall on my system (again not scientific) and would occasionally junk up the terminal when it got fed something strange. This could be a problem with fzf or it could have been a problem with how I was using it.
On the other hand, sk at the CLI has been rock solid and very fast. skim as a library needs better docs and has a few other teething issues, but I'm using skim right now, because it feels faster, and because I use it as a library, there is some mental continuity between the two. Recognize and respect fzf in this space, it's just sk is doing it better for me, for now.
Unfortunately that's only superficially true at this point. I recently removed sk support from a project because I was tired of special-casing for it. (ZFSBootMenu).
That first exposure to fzf brought the biggest change to my workflow in years.
I don’t understand what it does. Is it like an alternative diff or is it a patching utility based on a specifically formatted file?
It formats that output, and then might typically be chained into `less` for actual paging.
[I co-maintain, just issue triage really, a similar alternative called `diff-so-fancy`.]
dsf = "!f() { [ -z \"$GIT_PREFIX\" ] || cd \"$GIT_PREFIX\" && git diff --color \"$@\" | diff-so-fancy | less --tabs=4 -RFXS; }; f"For those that haven't tried yet, and want an entry point, I'd highly recommend you play around with the 'fzf' key bindings and completion scripts for zsh[0] to see what's possible. A little app of mine[1] also has an example of what one might call the minimal viable hot key script for you (note: for skim or 'sk', a 'fzf' Rust clone).
[0]: https://github.com/junegunn/fzf/tree/master/shell [1]: https://github.com/kimono-koans/httm
git log --oneline | fzf
and interactively fuzz your way to the commit you're looking for. Having the ability to just update live with backspace when the search isn't matching makes a tremendous difference.I think I installed it differently on other systems previously, and those installs took care of the integration for me.
https://github.com/peteryates/dotfiles/blob/master/zsh/.zshr...
In my experience it's too fuzzy, and makes it impossible to find anything.
~/books_and_papers/causal_inference.pdf
^^ ^ ^^ ^ ^^^I still need to find a satisfactory way to do “find in files” with vim. I use a custom script to call ag and it’s enough, but a bit clunky at times.
I imagine you have a similar approach, what's clunky about it for you?
I also use vim-grepper (mapped to leader-g) for finding in files and populating the quickfix list.
Does that work for you? I thought that's what a fuzzy finder is
If I wanted all occurrences of lines that match a pattern I'd use vim-grepper (which uses Ag or ripgrep under the hood) and search with a regex.
If you're using Telescope you can use your fuzzy search to find the lines you want then use <C-q> to send them to your quickfix list.
For find and replace, I use spectre.
Does that work for you? I thought that's what a fuzzy finder is
You can use zsh's fzf-tab as a supercharged tab-completion. e.g. you can just do
some-command <TAB>
and it will put a fzf interface where the tab-completions would usually be, and you can pick whatever files you want. And if you instead do some-command -<TAB>
it will instead show you all the possible flags and their descriptions, which you can also pick from.I use this all the time on the terminal now. It cuts out so much pointless flow-breaking invocations of ls and man and --help.
https://pypi.org/project/iterfzf/
The python package also includes the fzf binary.
Just a small thing to add on to the awesomeness that is fzf!
I still use ksh these days (actually, the openbsd version, even on linux) and it behaves EXACTLY the same way as a bash shell to the uninitiated (ctrl+r, fc -l, etc etc etc)..
I have some little shell functions that I use for things, like 'git_branch()' which I use with some aliases (I have >200 shell aliases)..
ZSH has a fucking ftp client in it right? And it still just behaves like bash? What does it do on top? Am I missing something? :}
omz is a tool for zsh users, that is its purpose in life
Zsh has a lot more features than ksh, the functionality ksh has is the lower bound if it works for you great
If you enjoy DIY writing 200 aliases great, zsh like bash is more than path autocomplete and aliases it’s a lot more
I look at zsh alias features and my head explodes a bit. The glob patterns can get so complex, they look like Perl or sendmail config strings.
I think you may have just answered your own question -- it includes ready-made shell themes and plugins. Not everyone wants to work that hard (including me!).
Any command where you might be generating a long list of items you then want to select from can probably benefit from being piped into fzf.
But if you need to to do something more specialized you can pipe the output of a kubectl command into fzf and then use the ‘describe’ sub command on the selected item returned by fzf. Basically when you need to interact in someway then run a command on the output fzf can be great.
For a Ctrl-R replacement in the terminal, it never sticked with me, because getting more than 1 results was distracting.
Also, if I'm in a directory and want to open a file in vim that I'm not sure of its location, I do `vim` and then Ctrl-P.
I tried to incorporate it a few times in my workflow, but I couldn't see the value that would justify the overhead of having to learn a different tool.
I use it to interact with git, i.e.:
- checkout local git branch from curated list of branches fed through fzf
- cherry pick commits from the previous (@{-1}) branch, using fzf + preview showing each commit's "diff"
- pick recent SHA to git revert
- pick files changed from {master,main,blead}
- pick files currently uncommitted
https://github.com/zbm-dev/zfsbootmenu/blob/master/media/v1....
https://github.com/zbm-dev/zfsbootmenu/blob/master/zfsbootme...
I would to like to use it for my web-history. And maybe for webpages I have visited too.
another resource I found valuable early on: https://www.youtube.com/watch?v=qgG5Jhi_Els
EDIT: just realised this is the repo README by the fzf creator. he mentions Samoshkin's video also but it's worth repeating