 I want to share with you guys a really cool command line utility called Fuzzy Finder or FZF. FZF is really cool because it is essentially kind of like D-Menu or Rofi, except it's designed to be run inside a terminal, a terminal emulator or a TTY because obviously D-Menu and Rofi are both graphical applications that draw their own windows. Fuzzy Finder though is a command line utility, it has to be run inside a terminal emulator, but essentially it's very much like D-Menu. Let me switch over to my desktop and let me go ahead and open a terminal and I'm gonna zoom way in here. I'm in my home directory obviously, and if I just do FZF with no other arguments, it's going to calculate about 220,000 files, right, this is all the files that are in my home directory recursively. It is essentially what Fuzzy Finder does if you don't feed it any kind of other arguments, and if I just click on a file, for example, Genie-ThemesMakeFile, maybe this is the one I was actually searching for, all it does is gonna print that file name as standard output. Now as the name suggests Fuzzy Finder, if I up arrow and run Fuzzy Finder again, I could actually search for something like I don't know my BashRC, for example, there's a test directory with BashRC, I think I used that as a test file the other day on camera for something. So in a lot of ways that is very similar to what happens with D-Menu. If I do Command-LS and I pipe that into D-Menu, for example, I get a list of all the files and directories here in my home directory inside D-Menu, and if I just click on one, you know, it just prints what I selected to standard output. So Fuzzy Finder, D-Menu, they kind of work the same way as just, again, D-Menu draws its own X window where Fuzzy Finder has to be run inside a terminal. And just like I pipe the command into D-Menu, I can pipe anything I want into Fuzzy Finder. For example, I could do printf, and let's go ahead and do %s, this is some value that I'll fill in later, and then a backslash in for new line, so I want a new line after all the values that I plug into printf here. And the values are going to be 1, 2, 3, I think that's enough. Let's just pipe that into Fuzzy Finder, and there is 1, 2, 3, I could actually search for, you know, whatever, and it just prints my selection out to standard output. Now of course, that's not very interesting just printing the standard output, typically what you'd want to do is you want, you know, some command, and you're going to take the output from that command and pipe it into Fuzzy Finder, and then you're going to pipe the selection from Fuzzy Finder, whatever you choose, through Fuzzy Finder into something probably XRs and some other command, typically a format you would use. And I could actually show you that in action, pipe up arrow to that last printf statement where we were printing 1, 2, and 3 into Fuzzy Finder, right, let me escape out of that. What I could do is then pipe that into XRs and I could do touch, the touch command. So let's go ahead and run this. So let me choose either 1, 2, or 3. I'm going to choose 2. And when I choose 2, it's going to run touch 2. And now if I do an LS in my home directory, I should now have a file called 2. And I do. Now if I wanted to remove that, what I could do is I could up arrow, I'm going to do Fuzzy F, pipe this into XRs, RM for remove. So I'm going to, you know, get this list 1, 2, and 3 again, 1 and 3 don't exist. 2 does though. And I want to go ahead and remove that file. So let me hit enter and it ran remove on my selection, which was 2. And now if I did an LS, 2 is no longer there. That file has been deleted and cleared the screen. Now I'm actually in the fish shell right now. I'm going to switch over to bash because I'm going to do some things that I don't want to do any weird fish scripting. So I'd rather do bash syntax here. So what I'm going to do is Fuzzy Finder is really cool that it by default, all it does is that recursive LS. It just lists all the files recursively in the directory you're in. Because of that, you can kind of use Fuzzy Finder as a really a cool file picker. For example, if you're somebody that's always in the terminal and you're always opening projects using a text editor such as Vim, you could do Vim space and then you could do dollar sign and then inside parentheses, you could do the Fuzzy Finder command. And what it's going to do is it's going to run the Fuzzy Finder command and it's going to give you a list of all the files recursively in my home directory in this case. And whichever one I choose, it's going to open that in Vim. So again, here's all of these files and maybe the one I'm looking for and I see one called gedit.com. I could do a quick search for it. Maybe that's the one I want. I hit enter and it automatically opens that in Vim. That's really cool. Of course, Vim was just an example. You could actually do that with any text editor. If you wanted to do something with Nano, there is me opening a quick file in Nano. Or I could do, you know, Emacs. I have my Emacs alias to my Emacs client. But you know, if I wanted to, I don't know, search for my dot bash RC, which apparently I have several dot bash RCs on the system. But if I wanted to open one, I just hit enter and it opens that in Emacs. Fuzzy Finder does have a cool flag, the dash dash query flag, where you can automatically fill in some string you're searching for. That way you don't have to type a string. So for example, dash dash query and then Linux gives me all the files that included the string Linux somewhere in the name. You can see it's down here in the prompt. I didn't have to type it. So that just saved me from having to type that. Now let me hit escape out of that. And what you could do, again, you could do something cool, like I could CD into my videos directory. For example, maybe I wanted a little script or maybe even just a little bash alias that all it does is it searches for video files on my system. And when I choose them using FZF, it opens them automatically in MPV. Well, I could do kind of like I did with the text editors MPV and then dollar sign FZF. But since I know all of my videos all end in mp4, right? That's the extension I could do dash dash query. And then I could make sure mp4 is a string that it searches for automatically. And that way it automatically filters out all the other crap that may be in my videos directory, because maybe I have some Caden live project files, or maybe I have some image files, you know, for video thumbnails, you know, things that are not proper videos. So this way it only gives me the MP4 files. And if I wanted to search for one, for example, this is a logo drop here that I sometimes add in my videos, it's going to be loud. But if I hit enter, there is that playing in MPV. Let's close that out. Some other possibilities for scripting. I mean, you could do PS, you know, to see the running processes on your system, I'm going to give it PS and the following arguments here AUX. And essentially, it's you know, a little system monitoring application and we could pipe that into fzf. And this way I can search for a specific process that I want to kill. For example, obviously, I have the alacrity terminal running right now, I could search for all the processes that have alacrity as part of the name. If I hit enter, you know, I just get a particular line outputted to the terminal. Now I don't need all of that. For one thing, it doesn't kill anything. But if I wanted to make this into a proper little kill script, what I would eventually have to do is pipe this into xargs and have it run the kill command on the process ID, which is the second column here. So what I first need to do is I need to after I choose it with fzf, I need to pull out the second column. So the easiest way to do pulling out that column is probably with AUX because of the way this file is formatted. So I'll do AUX and then inside single quotes, I'm going to do opening and closing braces as well, print dollar sign to then pipe all of that into xargs and it's going to run the command kill on the output. Because the output should be the process ID, that's what AUX is going to pull out for us. So if I did this correctly, now if I want to search for something, for example, I search for alacrity, which is the only alacrity window I have open and if the script succeeds, it'll kill this window. And that's exactly what happens. So let me open a new terminal switch over to bash and let me zoom back in. One thing that I like to do with D menu and you could also do this with Fuzzy Finder is when you make a selection in the Fuzzy Finder little menu, instead of just printing that to standard output, why don't you copy it to my clipboard that way I can use it later? Well, I could do something like this. So once again, we're just going to print one, two and three inside Fuzzy Finder and whichever one I select, it's then going to pipe that into xclip-r-selection space clipboard. It's going to copy that selection over to the clipboard. So here is this running in Fuzzy Finder. Maybe I want to if I hit enter, it just copied two to my clipboard. If I do a control shift V to paste in the terminal, you can see two was sitting in my clipboard. If I up arrow and run the same command again, this time choose three and then paste, you can see three has now been copied and it's sitting in my clipboard. And really, I could edit some of my D menu scripts to just be Fuzzy Finder scripts. If I switch over to this workspace, if I do a super P B on my system, I have this script that sets a wallpaper. So if I choose set for set wallpaper, it's going to open sxiv, right? And it's going to give me a preview of the wallpapers in this particular wallpaper directory. And if I choose one and hit M to market and then close the window, it just set that wallpaper for me. Well, I could do something similar probably with Fuzzy Finder. So what I would do is I would need to LS all the contents of my wallpapers directory. So I do command LS. And the reason I'm prefixing LS with command is I don't want LS to be run with any aliases because my bash RC has LS alias to something else. So I'm going to do command LS. And I want it to list everything in my home directory slash wallpapers directory. So there are all 300 something wallpapers I have in that particular directory. And then all I would need to do is pipe that into Fuzzy Finder. And there is all of that in Fuzzy Finder. And then what to do with this once I select something with Fuzzy Finder world, we're going to pipe it into x args, meaning take the outlet from Fuzzy Finder and pass it on as an argument for this next command, the command is going to be the x wallpaper command x wallpaper. And I'm going to do dash dash stretch. So it fills up the screen and that way adjust the size of the wallpaper in case it's not exactly 1920 by 1080. So if I run this command, I'm going to get all of my wallpapers in this list. And I could just up arrow and just choose one like wallpaper number 15 here. And if I hit Enter, let me go to a new workspace. That is the same wallpaper. So I don't think that it actually did anything yet says no such file or directory. You know why this doesn't work is because x args is actually trying to run that command on 0015.jpg. And we're in the home directory, but we're actually running the LS command on wallpapers, but 0015.jpg does not exist in the home directory. So the way I would fix this, I would fix this so it runs this command on any directory that you're in, but I would do a command LS dash D for I don't want you to do any recursive searching or recursive listing just list everything in this directory, but no subdirectories and do the dollar sign capital P WD. That's a shell environment variable. It prints the current working directory that you're in and then do slash asterisk. So list everything, every file in this directory, and then pipe it into fzf into x orgs x wallpaper dash dash stretch. And I'm not going to find any wallpapers in my home directory. But now that I've done that, let me escape. Now I would just have to CD into my wallpapers directory. And let me up arrow and I would probably just alias this I would alias this to I don't know wall. I don't know if that's already a shell command, but I probably put this in my bash RC or something. And now if I run this, yeah, now I get the full path to the files. And now if I choose one, for example, wallpaper eight, you could actually see it changed. And if I get out a full screen here, I'll make this a little smaller so you can see the change I'll up arrow, I'll run the command again. And this time I'll choose wallpaper 10 up arrow wallpaper four. So pretty cool stuff that you can do with fuzzy finder. Now I actually haven't made a proper video on fuzzy finder before, even though it's one of the more popular Linux utilities out there. And the reason is, is because it's so similar to things like D menu, for example, I have so many of my scripts designed to use D menu, which again draws its own windows not designed to run in a terminal. And that could be useful, because they're a little different, you know, which one you may prefer, maybe you have use cases for both. For me, I can tell you some of the things that like if you're going to convert some of your D menu scripts to use fuzzy finder or vice versa, one of the things you need to anticipate with fuzzy finders, like if you're doing a selection and fuzzy finder, and it starts a process that's going to run like, Hey, play this video in MPV, for example, or play some audio with whatever MPV as well. And you're going to have this running process that's going to take up the terminal. So make sure you design these scripts with fuzzy finder with that in mind, because this is stuff you don't have to worry about in something like D menu, because it's going to run that background process. No problem. D menu is going to go away. You're not going to have a window that's busy just taking up, you know, part of the screen the way you will with these terminal programs like fuzzy finder. And I know some people are going to wonder, Hey, can I just quickly substitute fuzzy finder for D menu in like your your D menu scripts that you already have on your system, you can't really you have to tweak it a little bit. It's not as easy where like D menu and Rofi are very easy to swap, you just replace D menu with Rofi and a script and it all works because they have the same flags, the same options. Fuzzy finder unfortunately doesn't have the same flags as something like D menu. For example, the D menu prompt flag is simply dash P space name of prompt fuzzy finder. You actually have a different prompt flag. If I go back to the terminal. Fuzzy finder has the dash dash prompt flag. And there's no space that has to be dash dash prompt equals, you know, whatever name you want to give the prompt, because it's not like D menu dash P space name, you know, it's a little different, right? So because of that, you just little minor tweaks to your scripts, but seriously, it would probably take just a minute or two to convert any D menu script over to using fuzzy finder. And if you do a quick search online, you search around GitHub, get lab, you're going to find people that are doing all kinds of neat things with fuzzy finder, turning fuzzy finder into a full blown file managers and things like that. You can get really creative, depending on, you know, how invested you are with scripting. Now, before I go, I want to thank a few special people. I want to thank the producers of this episode, Gabe James Maxim, Matt Mimic, Mitchell Paul, Royal West, Harmer Dragon, Bash Potato Chuck, Commander Ingery, George Lee, Methodist Nate Erion, Paul Peace, Archon Fador, Polytech, Realities for Lust, Red Prophet, Roland, Dools, Devler and Willie. These guys, they're my highest tiered patrons over on Patreon without these guys. This quick look at Fuzzy Finder, it wouldn't have been possible. The show is also brought to you by each and every one of these fine ladies and gentlemen. All these names you're seeing on the screen right now. These are all my supporters over on Patreon. I don't have any corporate sponsors. I depend on you guys, the community to support my work. If you want to see more videos about Linux and friend open source software, subscribe to DistroTube over on Patreon. All right, guys. Peace.