 One of the most common questions I get from viewers of the channel is about learning shell Scripting especially those that are new to Linux just switching to Linux and they really want to dive a little deeper into Linux They want to learn some basics They want to learn the basics of the bash shell and bash scripting And I think one of the best tools to play around with to learn bash scripting is actually D-menu for those that are not familiar with what D-menu is. It's basically most people think of it as a run launcher It's more than a run launcher if I hit this key binding here I get a run launcher here at the top of my screen and I can start typing for a program that's installed on my system like Alacrity I could hit enter and it launches the Alacrity terminal But D-menu is more than just a run launcher D-menu actually You can pipe any information you want to into D-menu and D-menu will display it as a menu and because the Possibilities are endless of what you can do with it, especially once you get into scripting with D-menu I think it's a really nifty little tool for you guys to start using to practice your shell scripting So in preparation for making this video I knew I was gonna make this video of several days ago and what I wanted to do is I went into some of my Personal D-menu scripts and I started cleaning them up a little bit getting them ready for you know Displaying to the public and what I did is I actually created a repository over on my git lab if you go to git lab Slash DWT one slash DM scripts for D-menu scripts. Not very original. This is a repository I created I've got I don't know seven or eight of my D-menu scripts listed in that repository for you guys to check out I'm not a programmer by trade So there may be errors in the code some of the scripts are very quick and dirty scripts that I just threw together Just mainly as proof of concepts. So let me show you some of these scripts I'll show you a little bit of the code how the code works and I'll show you of course the scripts in action So let me switch back over to my desktop and I open doom emacs here This is my text editor of choice these days doom emacs I'm going to toggle on big font mode. So you guys can see really big font and I'm going to navigate to this directory here DM scripts and I'll just open it up in dear Ed Which is the built-in file manager here in emacs and I can navigate down and I have several scripts here I think the one that is the simplest as far as the concept is this one here that I call DM comp and it's very It may look complicated, but it's actually dead simple This thing literally I could have wrote it in like two minutes had it not involved so much typing It really involves this Declaring and options array So declare dash a we're going to declare an array and we're going to name it options Equals and then each line is an option in this array And then we're going to pipe all of these options into D menu Now let me show you this in action. So we hit the key combination for this here And you see I have this run prompt that says edit config and it lists Everything that was in that array. So let me escape out of that and I show you once again This is the array now dollar sign home in all caps, of course expands to my actual path to my home directory Which is slash home slash DT. So they do that again You see dollar sign home is replaced by home slash DT in all of these now again I didn't put a lot of thought and effort into this script It's a very quick and dirty script that I just threw together kind of fast But my thinking behind it was I wanted to create this array and in this array all of these options I wanted each option to have three fields I wanted the name of the program that I wanted to edit that particular config file for And then the second field is going to be a dash And then the third field is going to be the path to the config file that I want to be able to edit I know that that may seem a little strange, but what I'm going to do is later I'm going to through the magic of the awk command awk is a command line program that allows you to pull certain fields out of text You know, I'm going to pull the first column out of this later And I'm going to pull the third column out of this later, which is the path to the individual config files themselves So let's get past the array because really like 80% of the script is the comments at the top Me setting a variable for the text editor I want to use because of course these config files need to open in a text editor and I'm going to want them to open in Emacs So that's why I set this variable later. We'll use that variable in a bit And then most of this is declaring the options array here And then listing all of the config files that I commonly edit So I created that list and then down here I have a piping the above array into D menu So I created choice. So this variable is going to be called choice And it's going to run the command printf we're going to print everything in the options array That's what the at sign it means. It means we want all members of the options array printed out And I want you to pipe that into D menu dash I for searching for case insensitively Dash L for I want it to be a vertical list and I want the number of lines to be 20 Dash P is the prompt flag for D menu meaning what prompt do you want And then in single quotes, this is the name of the prompt edit config So again, I do the key binding to launch that you see edit config as the prompt you see the array Now that's not very useful until you also finish the script and tell it what to do when you select an option. So what happens when I select, for example, the very first thing in the array, which is alacrity, it's already highlighted my alacrity config. Well, what I want you to do is if choice remember choice was the variable we created for everything being piped into D menu. So if choice equals quit the very last thing in the array I called quit I wanted to quit option just in case people want it out without doing anything. So if the choice is quit then I want you to echo program terminated and an exit one. So I just want you to exit out. Now if they choose something that's not quit so else if choice then I want you to do this I want you to print the choice meaning if I choose ZSH for example, print that entire line. But what I want you to do is I want you to pipe that into alch and I want you to print dollar sign capital N capital F that means print the last field the last field is that field. I only want the path right. So the fields are separated by spaces by default and also ZSH is a field the dash or the minus symbol that's a field and the path is a field. So I wanted all to print just the last field for us. Now what do I want it to do with that path to that config file well I want you to then run the command dollar sign DM editor that's the variable we set at the very top DM editor is basically my command to launch Emacs. So I want you to run Emacs path to the config and that really is the script like there's really nothing else to the script it was very quick and dirty is very easy if I wanted to I could scroll down here and go to my DWM config dot def dot H if I hit enter it launches it inside Emacs it looks like I got a maybe an error inside my config dot def dot H I'm not sure what that is let's try a different file go to my DWM Emacs config dot EL we'll launch that and there is that and we'll close that so very simple script but it solved a problem that I wanted to solve you know I just wanted a quick way to quickly open some of the common config files that I edit all the time so that was the purpose of this script why I named it DM comp for config let's check out one of the other little scripts that I've played around with here lately I created this one the other day called DM search years ago there was a really neat little script called surf roll that was created by Julian Assange that allowed you to search various search indices on the internet that script hasn't been updated in years and a lot of the options that are built into that script now are no longer working their links that are dead so I just wanted to create a simple little search script so the format of this is very similar to the last script I basically typically use the same kind of format I just did a variable at the top where I made a variable for the browser I want to use because this is going to be searching the web so I want to search the web obviously using a web browser the last script of course we needed a text editor because we were editing config files so I set DM browser equals the brave browser and then I created another array declare a for array and then I named the array once again options I'm not very original with these names and then once again I wanted to have three fields in each option the first field is just the name of the search engine that we're searching in this case Amazon and then the next field is again the dash or the minus sign and the third field is going to be the URL for the search engine and it needs to be a search URL minus the keyword that it searches for so if I was searching for I don't know distro tube this URL it would actually read out this so what I need is all of these URLs to be in the format or the it's the URL you know searching for a keyword or a query search and I need it to not include of course the keyword because when the keyword will constantly change we're going to add the keyword using d menu I've got all of these various search indices in this array again it's very easy this was not complicated the complicated part is going to each search engine and searching for something and getting the correct URL but scripting it is very very easy and then at the end I've got some while loops while kind of like if you know if then do this if this is true then do this while is while this is true do this and just keep doing it that that's what basically a while loop is I don't want to get way off into explaining that but it's not terribly different than what we saw in the last script and I have this here while engine we're going to have a variable called engine here in a minute do this and what I'm going to do is I created this variable engine list and what I want that to do is I wanted to print all of the options so every member of the options array I want you to once again pipe it into d menu with the same flags as the script we looked at before except the prompt is now choose search engine so if I do the key binding to run this script you say choose search engine and then once again every member of that options array which is the search engine hyphen and then the url now I don't really need the url displayed in this menu I could actually clean that up but it's fine being there for now the next thing I wanted to do was I wanted to take that search engine list which is once again this entire list here I wanted to awk the last field so that's what this is I want the last field which is the url and then I also wanted to awk the first field which is just the name of the engine because I'm going to use that in the next d menu prompt because I'm going to have this query down here query and then we're going to d menu and the prompt is going to say searching engine what is engine well engine is going to be taking the engine list and awking the first field so if I happen to choose youtube the next prompt is going to say searching youtube let me show you that so let me this is the first prompt where we're getting all the members of the array let me search for youtube I'm going to hit enter and the next prompt says searching youtube what am I searching youtube for I'm going to search for distro tube if I can type and you guys didn't see it but off camera here let me show you guys this it actually just searched in my brave browser for distro tube on youtube so that's just briefly what I've done with a couple of scripts here of course that was a search engine script you guys saw the previous script which was a script where I could edit config files that I edit on a regular basis let me show you just briefly one more that I've been working on I called this one dm red because it's for reddit it's going to be using d menu as a way to view reddit using a command line reddit viewer called radio which I think I did a video about radio a while back anyway this one gets a little more complicated because what are you going to do first you have to choose a subreddit from the options array here which I called not options this time subreddit underscore the list was what I named the array and then what happens when you choose one of these subreddits well I want you to give me a list of posts the latest I don't know 20 posts from that subreddit okay what happens when you select a post from that subreddit well I want to you just display the main message from that post I selected so I've already got three different things going on as far as you get d menu and then you choose something and then you get a second d menu you choose something and then you get a third d menu etc and I've this is very much a work in progress there's probably a lot more I'm eventually going to try to add to this thing but right now what I've got don't have a key binding for it yes I do you see the very first prompt choose a subreddit let me go down and I want to choose r slash command line and then I get a second d menu last 20 posts on r slash command line and I want to read actually I want to read that very first post it says the new shell a new type of shell I like the new shell let me read this post about it and if I hit enter it should have piped that message into a zenity dialogue box and the reason I'm piping it into a dialogue box is because by default you don't have text wrapping in d menu so you can't really read a lengthy post in d menu you have to pipe it into something else you know open it with a text editor or web browser whatever I just wanted it in a zenity dialogue box but it doesn't look like there was any text there let me try that once again and this time I'm going to go to the arch linux subreddit and I'm going to read we'll read the frequently asked questions from the arch subreddit okay and this is a more normal kind of post maybe there wasn't any text in the post I selected before but you can see it gets piped out into this zenity dialogue box which allows me to easily copy that text if I wanted to or you know if I don't want to do anything I could just cancel or I think escape also works if I escape out of it it exits out of that part of the script anyway I don't want to go over every single script that I had in this just very briefly on camera I will show you them in action so I had a scrot d menu script I called it dm scrot it actually uses maim maim as a command line screenshot utility and I gave this thing a ton of options as far as taking a scrot fullscreen or just the window I'm currently on or I could select a region I could copy to a clipboard I could take a screenshot of monitor one monitor two monitor three I could copy a screenshot of monitor one two three etc so there's a lot of options in this menu anyway I just hit enter and you know and I get a screenshot and the screenshots actually get posted to a screenshot folder in my home folder unless of course I choose one of the copy options and then it just copies that image to a clipboard that I could then use to paste into I don't know gimp or whatever it is I need to paste an image into the other ones I have I had this one here which is just a kill menu you see the prompt says search for process to kill it uses the standard ps command a standard linux command line utility to search for processes and if I happen to choose one it will ask me do I want to kill it for example maybe I want to kill let me see something safe to kill here Pycom and it's asking me do I really want to kill it it says kill and then the number of the process and then the name of the process Pycom if I hit yes it just runs the the kill command on Pycom but I do have the option to choose no to back out of it if it's a process I don't want to kill and another one I did was this one here which is just a simple shutdown menu so I can log out I can lock the screen reboot shutdown suspend quit so if I wanted to well I'll show you the lock screen that's a safe one to do while recording that locks the screen until I start typing my password and if I type my password correctly you know it unlocks that uses a suckless screen locker called s lock or slock I'm not exactly sure how it's pronounced I actually did a video about s lock a while back so if you guys are wanting to learn some shell scripting I strongly advise you to start playing around with something like d-menu or you could also do this with rofi you can pipe things into the rofi run launcher d-menu is very simple to use though that's why I recommend it it's just a fantastic program anyway but you know do what I did you know that search engine script was a problem I wanted to solve that's why I wrote that script find a problem that you want to solve and make it happen with some basic shell scripting and then piping it into d-menu now before I go I need to think a few special people I need to thank the producers of this episode absy delis gay blue Mitchell Allen a commie archv to 530 chuck david the other david dylan gregory louis paul scott west willy some other people I don't know I hope I get the names right I also want to thank each and every one of these ladies and gentlemen I would read the names but there's just too many darn names on that list the distro tube channel is sponsored by the community and if you'd like to support my work please look for distro tube over on patreon all right guys peace