 Alright I got a little time today so let's throw together a little video on something that might be educational or at least informational for some of you guys. So if you know the first thing about Linux you probably know that there is this command called man that you can run on the terminal. So if you want to learn about any kind of terminal command let's say the command ls you can just type in man ls and you get a full manual page that you can read and learn all the stuff about any kind of command. Okay you can even run man on itself and learn about man and all the different options you can use with it. Okay so here's the thing maybe there are some people I'm gonna throw together a hypothetical scenario because we're gonna do something involving pipes, involving lots of fun, standard input, standard output and hopefully it'll clarify some things for some people watching but here's what we're gonna do in this video. Okay let's say instead of let's say I'm bored by reading manuals on the terminal. Here's what I want to do. Okay I want a user interface where I have a menu of every manual installed on my computer. I want to be able to select one of those and then I want that manual to appear not on the terminal but in a PDF. Okay that's what I want to do and in fact I want to do it in one line, one line of shell script. I want to be able to do all of that. That is easily possible with pipes that's one of the easiest things to do just standard input, standard output that's all we're gonna do. So now if you watch the channel you probably already know some of the programs I'm gonna use to do this. Two of them in particular so I recommend you install these programs because they're great. One of them is D menu so D menu if you don't know the first thing about D menu let me show you. Let's say we have a file with you know two lines here's the first one line one and here's the second one and you can pipe a file like that into D menu and it's gonna give you a menu of the each of the lines and you can start typing one in let's say to press enter and it'll print that out the standard output. Now D menu by itself is useless but it's one of the most useful programs in the world. Okay and we'll talk about why well no I won't talk about why. I'll show you why in this video and by the same token there's a PDF viewer that is called let me actually just show you what packages I have installed. There's a PDF viewer called Zathura and the reason why Zathura is a great PDF viewer is because it can read from standard input and I'll show you why that's great in a second but so the two programs you should have installed if you want to follow along are D menu and Zathura although if you're a true subscriber you probably already have both of these installed because they're honestly fantastic programs. I'm not I'm not telling you to install them just for this command or something but they're fantastic and I will show you why. Okay so anyway back to man so let's say so again we want to have a menu of all the manuals on our computer and select one of those and we want a PDF of that to pop up and we want to do it in one line. So let's start by getting a list of all the manuals on our computer. Now one of the off if you type in man man you will know that one of the options to man is K and this is so basically the idea behind it is let's say we want to find something that has to do with law tech. Okay you can type in K and then law tech and all the manuals that have law tech either in the title or description will pop up now man K is actually the same thing as this other command for a Poe but you know some I always use man K because I don't know why not so that's a way of getting a bunch of manuals but you can just give period to print out every single manual so that actually gives us our list of all of our manuals automatically don't have to worry about that whatsoever. So now we want a menu of those and as I showed you just a second ago that's really easy we can just pipe that into D menu so if I pipe the output this list of manuals into D menu what's going to happen is D menu is going to give us a menu here with with all of the manuals in it now it's not very visible now I mean we can type something and we can type in DWM and select it but D menu has an option L that allows us to us sort all of the options I guess either vertically or horizontally however you can screw that but let's say we give L the you know the parameter of 30 that'll give us a list of 30 of these options and again we can type in like delete or law tech or anything else and we can select one of these and notice once I select one it prints the standard output okay that's great okay so keep this on one side I'm going to move this to another workspace so the other thing I want to do is let's say hypothetical let's say hypothetically we've chosen one of those man pages or let's say you know we just have the man page for LS how do I view that as a PDF well one thing that you can learn by running man man is that it has an option capital T and what that means if I just run man instead of running man LS that gives me this view here I can run man capital T PDF LS and what that does is it actually prints the manual to LS to standard output in PDF format so this thing that you saw right in front of you that's what a PDF looks like in text form so the nice thing about that is we can pipe that directly into the thorough and if you give the thorough this if you give it hyphen that means a read from standard input so if I just run this I now have the man page for LS as a PDF okay now this is there is not a PDF of this man page on your computer that's not what this is it's that man is converting it real time into a PDF it actually goes actually you can see down here it's actually a temporary file is how Zathara reads it in and it displays as a PDF in Zathara okay so that's great that's how you get a PDF okay so let's combine what we did just a second ago with this oh and I should say I might have mentioned at the beginning of the video but Zathara is a very modular PDF reader you are going to want to install I mean if you're outputting it as PDF you are going to want to install one of the PDF reading modules but you can also you could you know output it as PS as post script or something like that if you want to use post script instead but just be aware of that okay so let's combine these two commands so I get again back here so if we select like law tech or let's say we select a bit of it's going to output this entire line but really what we want is just the name of the manual so instead of running all that well after running all this that is going to give us this entire line I'm going to pipe it into all and I'm going to tell all only print the first word in that line okay so now if I run it and I select Biber now there's only this one line here or this one word here okay so now let's combine these two commands okay so here's our first one actually well just get rid of them because you know it's too much stuff on the screen so we're going to combine those with XRs so XRs is a command that can take standard input and can create a new command with that so here's what I'm going to do I'm going to run XRs I'm going to run it with the R option you don't actually have to that just means if XRs gets nothing it does nothing so XRs and then you are going to actually let me make a little smaller so things can fit together we're going to run that same man command so we're going to say man TPDF and so what's going to happen is XRs is going to read the standard input if we choose Biber it's going to be Biber and it's going to run man TPDF on Biber and we can pipe that into Zathura like we did just a second ago you all also have to type it right though okay so once we do that now we have this menu here so let's say you pick a Biber and now that is going to display our PDF okay so with one little line here we have basically taken a list of all the manuals we have given a user interface for the user to select an option and now we have a result we actually have the PDF okay so let's actually so you could take this and make it a function in your bash RC let's actually you know I'm the kind of person I like you know I actually don't like making functions there are reasons for that I like making independent scripts for something so let's make a name this script something like mansplain okay so let's say shell script and we'll just write it in here I'll rewrite it just to make sure so print out all the man mans actually let's get some syntax highlighting so print out all the manuals give me a D menu of all those manuals let me select one of them take that one of them and then print the first word of it then give that to XRs and create a command man TPF with that standard input the standard input is going to appear at the end here and then pipe that into Zathura okay now one of the reasons I actually like making independent scripts is actually because of XRs because XRs can it doesn't read your bash aliases it's it creates some kind of sub shell or something it but it can read your independent script so anyway so made this little script let's actually let's make this executable so now you know let's say I get rid of this all right I can run mansplain and it will give me this little thing here so let's say I want to learn about ST and that manual page now pops up okay so that's basically all you have to do so why did I do this video is it because I particularly now this might be useful useful for some of you guys you might want to have PDFs displayed you know for man pages maybe you want might want that I don't I don't particularly need it but my point here is just the kind of things that you can do just you again this is literally just one line of shell script POSIX compliant shell script all it is is pipes that is you are just taking one command and editing that text until you get a command that you want and then you run that command and that's all it is so you know if you want to get good at least the command line doing you you know shell scripting and other stuff the biggest recommendation I can give you is just get good you know have sort of a pipe like mentality and once you have that it actually all becomes easier so anyway that that's about it for this video I'll see you guys next time throw whatever suggestions you have in the comments and yeah have a good one