 Hello and welcome to a video from filmsbychrist.com. I am Chris, that's Chris with the K. Link in the description of my website today. We're gonna be creating a script just to make life easier, right? So if you're on a link system, you have package managers depending on what system you have. You have different package managers. I am on a Debian system. If you're on a Debian based system using some sort of app. So apt or apt get or I prefer aptitude. So if I was to use aptitude, I could search for example, if I was looking to install package, I could say search bash and it will list all applications with the name bash in it. And so then I can take one of those. Let's say I want to install bash. I mean, or have an install, but let me go sudo apt install or actually I can do aptitude install and I will give it the bash name. It'll ask for my password and I will run that. It's already installed. It will tell me that it's already installed and that is fine. So what I wanna do though is I wanna be able to have this list come up and then filter through that by typing and then grab multiple packages and have them all installed. And we're gonna do that using aptitude and FZF. We're gonna write a script. It's gonna be less than 10 lines long for sure. Maybe closer to five, but let's go ahead and just look at this real quick. So again, I can do this to search for the phrase bash, right? And what I can do is I can pipe that into FZF and it will give me that list and then I can type in something like top and there's bash top. I could enter and it returns that. If I want to select multiple files, I can say FZF-M. And now when I do that, I can say top. I can say tab on that one, tab on that one, tab on that one. And now it lists out all three that I had selected with the tab. Great, but of course we want to give it some sort of problem. So the user knows what to do. Dash dash prompt and then what we want it to say, we'll say select packages. And we'll make that look nice. We'll run that and now we have our little select packages. I can type in something like node and I can select whatever packages I want here. I typed node wrong, but it still filtered it fairly decently and we'll run that and list those out. Okay, we just want the package name, right? So that's the second column. So what we can do here is we can now put this into awk and I can do curly braces there or whatever you want to call them. And I'll say print dollar sign two, that's the second column. So now we still get our full list with the description. Again, I can say node and I can tab through those three and now it gives us a list of just the package names. But we want those all on one line but with spaces between them. So real simply, we'll just put that into tr. We'll say backslash n. So we're going to convert all new lines to spaces. Again, I'll just do node. I'll do tab, tab, tab or however many of these I want and then it lists them all in a row. Now we can just take that output and we can put it into our apt or aptitude or apt get command to download. So let's go ahead and start working on this as a script. So I'm going to say vim and I'll call this app search. You can call it appsearch.sh if you want. And my vim configuration automatically puts this header into all my script files, my shell script files. So that's good. You just need the bash shebang line there saying that this is a bash script. And first thing we need to do is the user giving an input. So when we run our script, is the user giving us a search query? So I'll just say, look at the first argument. Is there a first argument? If there is a first argument, we're going to say q equals whatever that first argument is. Now let's say the user doesn't give us any input when it runs the command initially. When they run the command initially. So we'll say our or operator, so pipe pipe, we're going to use the read command dash p and give it a prompt. And we'll say enter search query. Whoa, there we go. And then we will create that variable q. So we're either looking at, did they pass it when they typed in the command, if not request it? And then we'll check, did the user actually give us anything? If they didn't, well then we're just going to exit right there. Okay, and real quick, just to show y'all echo out q. We'll save that. We will make it executable, like so. Now, again, we have our script and our directory here. I'll dot slash that. And if I give it something like bash, it will echo out bash, cause that's why I typed. If I give it nothing, then it will ask me for something that can type in bash or whatever I want to search for. Great, now we're going to move on. We're going to run our command that we created earlier. And put that into a variable. So let's go ahead back into our script here. And just to save time, I will copy and paste. I'll delete that echo line, cause we don't need that. That was just for demonstration purposes. So I am going to say this. We're going to say, we're running our aptitude search with our query up here as long as something was passed. Otherwise we've already exited. We're going to put that into fcf, search, make sure we're selecting multiple files. If we need to, putting all those on one line and putting that into a variable called pkg. Now we want to make sure that we actually selected stuff. Cause if we didn't, we're just going to exit at this point. So we're going to say, okay, pkg, should we exit now? I don't need the quotation marks around these variables when we're checking them. But just to be consistent, I'm either going to have them or not have them. So now we have quotation marks around that. Okay, so again, now I can run our script. I can say bash, it's going to search for bash. And now I have a list I can filter through. So I give it an initial search and then it will give me a list that I can filter through and select from, right? And, or if I didn't, I can say something like node, right? And it's going to give a long list node stuff and I can say bash, there we go. I selected one, okay? So let's finish it off. We now, as long as we have selected something from that list, we are now going to run this. We're going to sudo apt install the packages, right? So let's go ahead and give that a try. I will run our script. I'll say bash and I will just check things I already have installed like so just so we don't install anything I don't want. We'll run that and you can see all those are up to date. If they weren't, they would have been installed. And if we were to not give anything here, I could type bash here or whatever I want my search query to be to narrow down the list. If I don't give anything, it exits. If I was to give it something and I was to go here, let's say I was to type in stuff that doesn't exist and I have nothing selected. It should exit out before it gets to that. So again, we have a nice little script here. One, two, three, four, five lines of code. And now you have a quick way to search through packages. Not that it was hard to do it with just aptitude search but now it's able to filter through the list a little bit quicker and easier. So now instead of running aptitude search query find the package name aptitude search install or aptitude install package name. You just run once you put this inside your system path your app search, search for your package, filter the list, select multiples if you want and it's installed. I'll put a link to this script in the description of this video. I hope you check it out and I hope you find it useful. Please visit my website. Again, filmsbychrist.com, that's Chris of the K and there you can also find links to my Patreon page, my Libre account and my PayPal account if you could support me somehow financially that would be amazing and I'll stop singing if you do that for me and if not I do thank you just for watching. Sharing this video with other people who think might like it would be awesome as well. Giving it a like and a comment would also be appreciated but if anything I just hope that you have a great day.