The Amazing Interactive Command Line Fuzzy Finder (fzf)
ฝัง
- เผยแพร่เมื่อ 11 ก.ย. 2024
- Have you heard of the command line tool 'fzf', aka. the Fuzzy Finder. It's an interactive Unix filter for command-line that can be used with any list. It's similar in concept to graphical tools like 'dmenu' or 'rofi' except 'fzf' is a CLI tool.
REFERENCED:
► github.com/jun...
WANT TO SUPPORT THE CHANNEL?
💰 Patreon: / distrotube
💳 Paypal: www.youtube.co...
🛍️ Amazon: amzn.to/2RotFFi
👕 Teespring: teespring.com/...
DONATE CRYPTO:
💰 Bitcoin: 1Mp6ebz5bNcjNFW7XWHVht36SkiLoxPKoX
🐶 Dogecoin: D5fpRD1JRoBFPDXSBocRTp8W9uKzfwLFAu
📕 LBC: bMfA2c3zmcLxPCpyPcrykLvMhZ7A5mQuhJ
DT ON THE WEB:
🕸️ Website: distrotube.com/
📁 GitLab: gitlab.com/dwt1
🗨️ Mastodon: fosstodon.org/...
👫 Reddit: / distrotube
📽️ LBRY/Odysee: odysee.com/@Di...
FREE AND OPEN SOURCE SOFTWARE THAT I USE:
🌐 Brave Browser - brave.com/dis872
📽️ Open Broadcaster Software: obsproject.com/
🎬 Kdenlive: kdenlive.org
🎨 GIMP: www.gimp.org/
🎵 Tenacity: github.com/ten...
💻 VirtualBox: www.virtualbox...
🗒️ Doom Emacs: github.com/hli...
Your support is very much appreciated. Thanks, guys!
So cool! I'm glad you saw my question on Mastodon. An important difference with Dmenu or Rofi is you can misspell: fzf can search similar results taking into account interpolations of letters, missing letters, extra letters, etc. That's the "fuzzy" part. Sounds like a detail, but in real life that's what makes it so fast and efficient to use.
At my previous workplace, a colleague installed fzf on one of the remote servers, and I discovered that it made ctrl-r a dream. The history search became a LOT easier. I admit I have no idea how he made the bash history search use fzf rather than the default, but it was wonderful.
fzf comes with a few scripts that are included /usr/share/fzf/. You just source them in your bashrc or zshrc.
The key-bindings scripts come with three keybindings, also. ctrl-r for history, ctrl-t for files under the current dir, and alt-c to cd into dirs under the current dir.
Thanks DT! Here are a few aliases that I use with fzf. They might be useful to others. Especially the ones with preview part
hf='history -100 |fzf'
mpf='cd ~/Videos && mpv "$(fzf)"'
pf='fzf --preview='\''bat --color=always --style=plain {}'\'' --bind k:preview-up,j:preview-down'
sqf='sqlite3 "$(fzf --prompt "Please select a database: ")"'
vf='vim "$(fzf --preview="bat --color=always --style=plain {}" --bind K:preview-up,J:preview-down --prompt "Please select a file to edit: ")"'
You can turn these into functions which check whether the fzf result is empty or not before executing them. So, you won't open the program, eg :- mpv if no results are chosen
@@glidersuzuki5572 good point. But these ones are aliases. And "mpf" cds into ~/Videos first. I know there are some videos there. So (only after 'cd' to a folder) second program 'mpv' is started.
@@samoylov1973 I have the alias for vim. But sometimes I decide I have to do something before editing the file and I press ctrl-c but vim opens anyway
@@glidersuzuki5572 one possible way out is to press CTRL+Z == sends current process to pause state. You can decide what to do with it later. Either you kill it, bring to foreground with fg, or run in the background with bg. Hope, this helps.
Thanks as always, Derek!
A couple of thoughts:
1. (Use case between dmenu/rofi vs fzf) - if you work in an environment where other consumers of your scripts don't have the xserver/ xserver programs, fzf of bound to the terminal.
2. I like to use fd or find to get around the issue you experienced where the script only ran in the absolute path.
i.e: $ fd . ~/wallpaper/ -e jpg | fzf | xargs
Great thing about programming, so many different ways to a solution!
Just in case it helps some other viewers (nice touch using sxiv - I think - as a visual filter)
Fzf has some powerful options allowing you to build custom commands with a dedicated menu bar inside fzf effectively turning it into full blown TUI for many programs that may need it
fzf is awesome, changed my workflow so much
Fzf is life. Fzf is love
Better late than never, sir 😉😎
fzf man page finder/viewer:
apropos -s 1 . | fzf --preview='man {1}' --preview-window=up
Scroll with shift-up shift-down
fzf package finder/info viewer:
pacman -Q | fzf --preview='pacman -Qi {1}' --preview-window=up
Can modify for apt, dnf, etc...
Can add keybindings to install/remove selected package(s).
fzf project picker, Emacs inspired:
cd "$(find ~/projects -name .git -exec basename {} \; | fzf --preview "tree {}")"
(This is not how I do it, but it used to be how I did it more or less)
fzf git checkout thing for some reason
git log --oneline --all --graph | fzf --preview "God knows what" | sed 's/[*/\| ]\(\S\).*/\1/' | xargs git checkout
I guess. I hope.
You always introduce us to the awesome utility.
Thank you, it's a great tool. I needed something like this for a long time but I didn't know how to search for it.
Instead of "command ls" you can do it like this: "\ls"
True, but I'm not usually running Bash. Mostly spend my time in Fish and the backslash trick doesn't work there. But 'command' works everywhere. ;)
I knew about \ls but not command ls
Cool. I had never heard of fzf. Your home dir had 221K files in it. Mine had over 11 million. This box has been around a long time.
At that point I'd just do a fresh install, it's not worth your time to sort through all that or to even attempt trimming it down
@@Polar_Onyx Hahaha! You have no idea. That rig has terabytes of storage - all full (and all well backed up). It's pretty well sorted and organized. No trimming down will happen. I love to collect stuff.
I've learnt so much from this guy
COME ON! --preview is the reason of fzf! It's the reason to replace dmenu with a terminal with fzf in it! It can act like NeoVim telescope, or it can give you the manual of the program you're about to run, or a preview of a file, or stats about a system process..
The wallpaper setter combination could work really cool with feh.
I tried some other day to set a very low-res pixel art wallpapers, but nitrogen was incapable of not making an ugly blur of enlarged pixels.
Once I learned about feh I was relieved, cos it had a function to remove any ugly blurring from the upscaling. But it was tedious to put all those flags in the feh command...
a bash script + fzf could make a usefuyl combination of a pixel-art wallpaper chooser :)
I think I wrote a wallpaper setter using fzf a couple of years ago...
One moment and I'll link it if I find it
There's a lot to that program, you can use environment variables to customize its appearance!
That is awesome. Great video man!
I will use this more than sed/awk for sure. Thanks for the great video D.
I don't understand the comment - fzf, sed and awk do completely different things anyway, one does not replace the other two for any reason that I can think of.
@@terrydaktyllus1320 I mean utility wise, I use fzf more than sed or awk, not as a replacement.
@@dod_ytent9984 "I will use this more than sed/awk for sure."
I am just holding up a mirror to your own words - and what concerns me more is if you think sed and awk are "alternatives" to fzf, then you really can't know sed and awk that well in the first place.
"fzf" = "fuzzy file finder", it finds files, like "find" does.
"sed" and "awk" allow pattern matching and string replacement *INSIDE* files, i.e. once you have found the files.
So do you understand now?
@@terrydaktyllus1320 ok, i will try my best to be more clear. I know what sed, awk and fzf do, and i know that each perform separate functions. I meant to say, in my day to day, i need what fzf does more than what sed/awk does, thus i use it more than I do sed/awk. Along with that this was a callback to DT's awk and sed tutorials.
@@dod_ytent9984 You don't need to explain yourself, it's just important to be factually correct.
Someone corrected me the other day because I was wrong about something I said about ARM CPUs - I also say incorrect things sometimes too!
Guys, more people need to sponsor fzf. It has 57k stars and only 50 sponsors!!
Great Tutorial, DT! 👍
Fuzzy finder. I'm old. I was thinkin' Craigslist personalzzz
I wish i was like DistroTube in the aspect of being able to keep up with all those folders/files in my home directory😅. Normally if i dont need it for daily use i just put it on a flash drive😂
Seriously DT?!?! You have this Ubuntu Compiz video sitting on your home folder since 2014? Was it an Easter egg?
With you onboard linux still is an interesting section to explore.
Thank you for this extremely useful video - I don't always agree with everything you say but it's your channel and "you do you" - but I hadn't ever considered using fzf until your video today explained it so well, and that's from someone who started with Linux back in 1996!
I've just realised how useful fzf actually is.... though vim is still better than emacs!
I've written a "library" in fennel (works for fennel and lua) so that I can use lisp (fennel is lisp that works like lua) to write shell scripts using fzf.
I personally prefer Emacs over neovim though but if you are comfortable with lua, that's good
Hey DT! when are you gonna inspect Hyprland ? i think it's still needs some work but i was hoping to see your perspective on it.
That is a useful tool I was unaware of.
d menu +fzf is unbeatable
Very helpful! Thx!
We all want a fuzzy finder but as long as it doesn't take screenshots
How do I get the sugestions when you start typing? Is this another tool?
Thanks D,
ma I ask which keyboard is this?
How do you do to get command suggestions on terminal?
Apparently I downloaded a copy of this last year and never installed it. I guess this'll be the push to play with it.
I'm the same - I knew of it and took the attitude "maybe I'll check it out some time" but it took his demo here to make me realise how useful fzf can actually be. To give Brodie Robertson some credit too, he did a video on it a few years ago and that's also worth a watch.
Cool vid. Thanks!
You can make terminal apps run in the background with Ctrl+Z.
CP3🙌
Is there any fork with fzf with vim simple navigation
nice video thanks
I can't use two fzf in one command
"...calculate about two hundred and twenty thousand files...". I can't do that on my system. I'm over 2.5 million and counting...fzf hasn't stopped yet.
hey dt do a video about where to split windows: window managers, terminal multiplexes, vim/emacs windows, all off them?
I *just* recorded two videos on this lmaooo
There's some interesting-looking content in your channel, thanks for the heads-up.
@@terrydaktyllus1320 Thank you! I hope it's gonna be useful to you :)
There's a playlist on Linux related things, and also one on neovim if you use that / are interested in figuring it out
how can you remember these commands if you're not doing system administration everyday?? that's what kept me away from Linux. It's fun when you learn it the first time, but too much knowledge needs to be ingrained and maintained, to do uncommon things.
that's why I'm interested in there being a hybrid text-graphical interface, where mouse and keyboard form separate focus cursors. as you type the graphics change to show the content and the options, you can click to add to the text, without losing focus.
this would be a new compositor/server based on Wayland and Weston.
"how can you remember these commands if you're not doing system administration everyday??"
You make notes, read man pages and/or create web bookmarks to the sites or searches that you use regularly. I started with UNIX-like systems 30 years ago and I still do just that, I don't even try to remember everything.
Plus you can use shell aliases or "one line shell scripts" to shorten longer commands also.
Linux just gives you "a box of tools", you have to learn how to use those tools.
I started using this in Vim. Then, I kinda knew how to pipe things into fzf to search for things instead of files. But I totally forgot that fzf sent the ouput to stdout!
Okay, but why do you have a problem with stdout? Did it steal your /dev/random and give you predictable output?
@@anon_y_mousse I didn't have a problem with it. It simply did not occur to me I could pipe the output from fzf to another program, like mpv, for example!
Anyway, now I know.
@@ecavero1 So if it sent it to stderr you wouldn't have liked to use it? I can understand that complaint, I hate having to redirect stderr for such programs, ffprobe being a prime example of such annoyance.
Problem with these powerfull tools is in ordinary life you very rarely have usecase for this
King Knoll
Bashirian Way
Hey distrotube, you are the greatest youtuber ever. Thanks for your support on our open source software and community. It means the world to me and billions of other people.
Robonuggie has played my games before and that was amazing. So yeah, I just love making open source projects.
Hey new Linux Trisquel 11.0 2023
Aniya Village
Roberts Circle
482 Roberto Plaza
Zed*
Lesch Loop
Garcia Mark Perez Eric Young Frank
Botsford Union
First.
I missed it by that much.
Ah,
I Hate Command Lines