 You guys know I love playing with man pages. Well a couple of weeks back I came across a really interesting script called macho and this fellow here named high fish He wrote this blog post sharing with the world his script for this macho Man page viewer and if I pull up a terminal here and I can actually show you guys what macho does Let me go ahead and run the script This is macho it is a man page viewer and if I just start typing maybe I'm searching for LS Or maybe I want to search through this fuzzy finder list here You see I get a preview window by the way Over here on the right side. It's really cool And if I just hit enter on whatever it is I'm searching for maybe I was searching for LS CP You know I could hit enter and I could actually read the man page of course cue for me to quit out of the man page So that is basically what the macho man script is it's man pages with a little bling If I go back to his blog post here You can see that what we're gonna do in the script and I will show you the script here in just a second But it's a very simple bash script or shell script He's writing it in POSIX compliant shell and it combines apropos man The grip said and alt commands the sort command fuzzy finder of course And if you wanted to you could even implement this in a graphical run launcher such as D menu and Rofi And I may do that as well. Let me actually show you what the script looks like So I'm gonna go ahead and open this in VM. So let me open up macho dot SH here on my system But let me open up a another terminal here and I'm gonna clear the screen and let me zoom in here So you guys can see exactly what's going on because I thought it this script is so interesting I thought I would explain to you exactly what this shell script is doing to get these really cool effects here You know in this macho man page viewer So the first thing we want to do is I think in the script the first thing the most important section is actually this Section here this function here manual equals and then it equals this very long command here apropos Piped into grip piped into awk Piped into sort piped into fuzzy finder and finally piped into said exactly what is he doing? Well, let's describe all of these commands first of all you guys know what the man command is man followed by a Program name gives you the man page for that program so I could do man LS and get the man page for the LS command apropos searches man pages for a string all your man pages So if I did apropos space and did I don't know man Let's search for all the man pages that have this particular string in them man and There is a bunch of man pages that have that three letter string ma in in it So we had a bunch of stuff returned one thing you need to know what he's doing here apropos dash s That is a flag as far as the sections of your man pages because when you look at a man page Let me go back to the LS man page You have sections you see LS and then in the parentheses here one that is section one and Just because it has section one there are a bunch of possible sections in a man page You could have sections zero through I think eight I'm a little fuzzy on what all the sections are but man pages have various sections and those sections kind of Define what that section is about for example if your section is about gaming and gameplay it will be in section Whatever, you know, it'll have a certain number that it should be in that man page So what I'm gonna do is I'm gonna copy this entire function here in the terminal here and let's start One section at a time and show you exactly what is going on here So the first thing we want to do Apropos and the the period sign basically let's get all the man pages on the system returned in apropos He's doing a love something a little different than what I just did with apropos period You know, he's putting some other information in there But it's basically the apropos command and what he's doing is then piping it into grip giving it these flags lowercase v capital e and then he's doing this Regular expression here and what it looks like he's doing is he's gripping out all the apropos Output that is section zero. He's basically trying to get rid of everything that returns section zero Because remember the man pages have multiple Sections that are possible and the ones that have a section zero I Guess don't really have any useful information. So he's just gripping all of that out And let me clear the screen and then he's piping that into all and the alt command that he's doing here It looks like he is printing the second column and then he's putting some space between it And then he's printing the first column. So I hit enter basically it is Reversing what was there before I go back to apropos just piped into grip You see this is what it looked like before now We're all king just the first two columns and then we're printing the second column Which is the number in the parentheses first then we're printing the first column second hope that makes sense That's what he's doing with that alt command So he gets this list looking like that then he's gonna take all of that and he's gonna pipe it through sort and he's sorting this So he's going to have it in alphabetical order, of course or in this case numerical order because he's sorting the first column Which is the numbers so now you know, you're getting this sorted from zero through eight And there is also a n section as well in man pages So n technically is the last when you're sorting it alpha numerically here clear the screen one more time And then finally what he's doing is he's piping all of that into fuzzy finder So now this is fuzzy finder So it's the same that we got before but now it's piped into this fuzzy finder prompt So you can actually do a fuzzy search so I could start typing for something like LS if I hit LS Nothing happens because you know what we did here in the command line We really didn't tell the terminal here exactly what we wanted to do once we selected something But anyway, then finally what he is doing is he's going to take all of that Apropos piped into grip piped into all piped into sort piped into fuzzy finder And then he's piping this into said with this regular Expression here and what it looks to me like he's doing here is he's getting rid of some parentheses Remember all the section numbers the man page section numbers were wrapped in parentheses So you had one wrapped in parentheses or n wrapped in parentheses. He's getting rid of those parentheses now But that is actually not what happened there Let me make sure that I did that correctly I may have not pasted that correctly and looking at this I think I did actually copy it correctly It does pull out the parentheses the problem is when I run this command You see we're piping apropos into grip and to all into sort into fuzzy finder We're never getting to the said part because once I select something into fuzzy finder It maybe it runs the said command to get rid of parentheses, but it's not really outputting anything So we can't actually see what that's doing. So all of that is is working correctly That's the main thing I needed to explain in the shell script is what this is that defines manual here And then what we're gonna do is we're gonna get this manual return Whatever it is we choose in the fuzzy finder list and we're gonna run the command man on it So let me show you this in action once again So I'm gonna run that macho shell script here and again manual It will be whatever we select in this list from this function here The apropo grip all sort fuzzy finder said function and it's gonna run said last once we actually select something So if I type man for example, and I select it it's gonna rip out the parentheses from man for example right here I select that it's gonna return instead of parentheses one man It's just gonna return one man and what it's gonna do. It's gonna run the man command on that I hope that makes sense and it actually runs the man command on that because man will not run this right here That is what it would be if we didn't have the said part in there And of course that returns an error But if I get rid of the parentheses because we piped it through said after we ran the fuzzy finder and then we run man on What is returned in the manual function there? That actually works and that's the most complicated part of the script here is this last section It's actually the most important section of the script the top half here is Interesting stuff, but mainly like this section here is actually for the preview window So if I go back and run the script what you're seeing over here the preview window So if I started typing something, I don't know like Firefox for example or fire C of G You know you get a little preview window of the man page And that is what is going on in the top section of the script here now that is all interesting But what about piping all of this into something like D menu or Rofi? Well, you could do that as well So let me cancel out of that and I also have on my system this script here macho dash GUI dot shill And it's very similar to the script We just read the only difference is once we run this manual function, you know And we select something instead of piping it into fuzzy finder You see the next to last step instead of fuzzy finder is now Rofi in this case And I will show you this in Rofi and then after we select whatever manual we select from the Rofi menu It runs this command here which opens a man page it converts it into a PDF Very interesting and then it pipes it into whatever PDF reader you have on your system For me, I have Zathura on my system. So to show you this in action here I'm going to quit out of that and let's go ahead and run macho dash GUI here And you see it launches Rofi and I could do a search for a man page Maybe I wanted to read the man page on DD if I could find it here in the Rofi menu And once I select it it actually opens it in Zathura here And you see it converted the man page into a PDF and then immediately launched it into Zathura And I personally think that is fantastic I think that is just a really neat way to read man pages I may go ahead and try to incorporate that into my workflow as far as I have a man page prompt Actually, I have man page prompts in all of my window managers I think I have D menu scripts that will launch man pages search man pages for me And most of my window manager configs and in Xmonad Xmonad has a specific prompt built into it That you can use to search for man pages But I kind of like this this ability to convert it into a PDF first and then read the PDF I think that is probably the way to go now because I don't use Rofi You know, I use D menu what I need to do is I'm going to go in here and edit this a little bit So instead of Rofi, I'm going to pipe this into just D menu itself So all I really need to do is get rid of that right there I'm going to write and quit and let's run the script again And now I'm getting D menu at the top here and then I could search for something Maybe I wanted to search for I don't know the cat command arrow over to cat here and hit enter And I get the cat man page of course again as a PDF very cool Now for those of you that want to explore this particular blog post a little more than what I did here on the video because this was a very cursory Overview of what he did and all this blog post is it's just some examples Of scripting and I took his examples and I made them into my own little scripts here And that's what I suggest you guys do. I'm going to link to this blog post in the show description Again, this is basically a shell script and it can be your own custom shell script I mean you can customize it to your heart's content depending on how complicated you want to make the shell script You can really do do a lot with a shell script like this now before I go I want to thank a few special people I want to thank Michael, Gabe, Heplo, Nate, Corbinion, Mitchell, Entropy, UK, Arch5530, Chris, Chuck, DJ, Donnie, Dylan, George, Lewis, Omri, Paul, Sean, Tobias, and Willie These guys are my highest tiered patrons without these guys this episode you just watch about macho man I've got to be a macho would not have been possible The show is also brought to you by each and every one of these ladies and gentlemen All these names you're seeing on the screen. These are not the village people These are my supporters over on patreon without these guys this episode wouldn't have been possible if you'd like to support my work You'll find dt over on patreon. All right guys peace