 When you switch to a tiling window manager One of the hardest things to do is learn the key bindings, especially if you've never used a tiling window manager before because chances are You've never used a keyboard centric workflow before usually you use just your mouse and your keyboard and kind of tandem and when you switch to a Tyler You're much more apt to use your keyboard because that's kind of the way tiling window managers are meant to be used So the question becomes how do you become more efficient actually using those key bindings? So today what I'm going to do is create a script called a key binding cheat sheet and What it will do is it will bring up a terminal with a list of all of the key bindings in your window manager So that you can gaze upon them and remind yourself what the key binding is you're searching for So this is not an original idea. So I just before I jump in I want to say that I got this idea Blatantly stole this idea. I should say from the Linux dabbler who did a similar script on Spectre WM a couple months ago He got the idea from awesome awesome and X monad have these things built in already So you if you're using those window managers, you don't need to do this If you're using something like DWM or Spectre WM or Q tile or Herb's Luff Maybe I don't know if Herb's Luff has Herp's Luff has it or not I haven't used Herp's Luff nearly enough to know that for sure so that's where we're gonna do today and I'm just going to say that this does not have the how-to words in the title because this is not going to be a Specifically a how-to. I have a pretty good idea of what I'm going to be doing But it's going to be all done right here live on camera So there's likely to going to be some mistakes. Let's just go ahead and jump in So the first thing we need to do is actually create the script Or a file for the script We'll just call this CS dot sh for now. And so we'll do touch CS Dot sh Okay, and then what we're going to do is make this executable. So we're going to CH mod plus X CS dot sh and then we're going to them into this So I have an alias called V So when you see me use the letter V, I'm just using n Vem So there's nothing special there about it's just regular Vem or in this case and then I guess so CS Dot sh I suppose I should zoom in here so that I can actually you can actually see this Okay, so now we have our file. So the first thing we need to do is create a shebang. So I always get the shebang wrong Because dyslexia happens or something. I don't know. So we do pound sign exclamation point slash bin slash bash You can also do slash sh it worked perfectly fine I'm not as much of a scripter as other people. So telling you what the difference is is something that somebody else will have to do I'm sure somebody in the comments will come along and say Matt. This is what the difference is between bashing sh They're two different shells. I know that part. I just don't know why you'd use one or the other. I don't really care Anyway, so the first thing we need to do is take a look at our configuration file. Now, this is DWM So the process for this will be a little bit different depending on what window manager using but the Skeleton of it at least should be the same. So my configuration file is located in my suckless folder, which is in dot config So we're going to CD into dot config suckless and Then DWM and if we do an analyst here, my configuration file is actually config.h. So we're going to Vim Into config.h now We'll change the size of this just a little bit And if we scroll down here Quite a bit We will see the beginnings of our key bindings and what we need to search for You're scrolling down more and more and more and more and more and more. Okay So what we're looking for is all of the key bindings we have Usually they have modkey or they have this xk underscore p now a lot of other window managers actually use this Syntax as well for key binding. So you may be able to even use this script but basically what you're doing here is you want to find something in the Configuration file that all the key bindings have in common. So whether that's Like in i3 I'm not sure what you'd you'd actually be able to pull out because everything is going to be a little bit different So like if I go to a different workspace here and we open up my sx hkd file And we look at this in here how I would go about making a Cheat sheet for this would be a little bit different because every single thing here and it looks a little different So I'd have to go through and I'd have to pull out super I'd have to pull out control and I'd have to pull out alt Because that's pretty much all of these have you know that thing plus this is a little bit harder because they're on two lines So instead of the way Grip works. It's only going to pull out the things that are on the same line So if you use sx hkd specifically for using like BSPWM creating a cheat sheet is going to be quite a bit harder But we're not in a BSPWM. We're on DWM. So it's gonna be fairly easy. So if we go back to Oops, that's not the right workspace. That was audacity You've seen how the sausage is made it's recording. That's what it does All right, so Now we have at least in DWM here and like I said The window manager user is gonna be a little bit different But what we need to do now now we have that commonality that we've pointed out we can Make this a little bit smaller. It doesn't really matter because we're not gonna need it So we can actually close it. So what we want to do is Pull out all of those things that have those certain commonalities and List them out. So what we're going to do is use the command Grip and what we're going to do is we're going to grep xk because if you remember and I shouldn't close that I guess but if you remember in the Configuration file every single key binding had xk underscore as a part of that line So if I do that I Need to tell grep what file I want it to search through so in this case. It's dollar sign home slash dot config Slash suck less slash DWM slash config oops, I can't spell Config dot H and I'm gonna actually give it that def dot H that way It's always searching the default configuration file just in case I've made some changes to the config dot H file nothing changes It's probably better to do this one okay, so Then we're going to do is Pipe that so this is the pipe this if you if you're not familiar the pipe is Located under your backspace key it when you'll need to do a shift in order to get to it So we're gonna pipe that in end into awk Now awk is a very complicated Command it's some people call it I guess a language in and of itself and I'm not an expert in using it like not at all So I can't exactly tell you precisely how it works in every facet. So There are great tutorials out there if you want to learn how to use awk. I Definitely would go through and check that out if you're more interested in Eventually I will learn more about it, but the process the the progress is slow So what we're wanting to do here is we're going to use awk to print out a Certain thing of each line that grep finds. So we're gonna Put in some brackets here. So these are curly brackets and then we need Single quotes and we want to use the command print Okay, and then what we want to do we're gonna do is go to a different workspace here We're gonna reopen up my configuration file So we're gonna just CD into dot config and we're gonna them config dot Def dot H and if we scroll down here again and what we want to do is We want to print out the second thing here. So we're gonna want to so this is the first key the modifier key and then we're gonna want to print out a the second thing here, which is the actual key press and then we want to print out the thing that it the key press does so that's number four, so we're doing two three Four and you'll see what I mean when I get there and then what we're going to want to do is Do the seventh one. So I've written this down before So this is two three four five Six and I believe seven it may print out this whole part here. I can't remember how it does it DWM is going to be a little bit harder here because the stuff here in the seventh is a little weird because you don't always need it But because sometimes your spot what you're spawning is over here in this like seventh column and The way Ock counts things is a little weird sometimes it counts things sometimes it doesn't count things. It's Very confusing. So you might have to go through and chain Kind of play with the the count and like I said, I'll show you what I mean by count here in a minute It's like said Ock is plenty confusing and I'm making it even more confusing as we go along. So Basically what we want to do is tell Ock to print the position of each of these things As after we as we run our command. So if we go back to this workspace here, we want to print dollar sign to Which is going to be this part here and We want to print dollar sign three Okay, which is going to be that xk underscore or whatever and then we want to do dollar sign for and Then from my counting at least prior to actually doing this video dollar sign seven Whether or not that was the right counting or not I don't know and then we want to close the single clothes and close the brackets and Then what we're going to want to do is save this and see what we get So if we write and quit this and we do dot slash CS dot sh We have some It's gone through and printed out stuff. So It's printed out the mod key the action key as I'm going to call it What the thing is doing so in this case in this first one here, it's spawning D menu and then it's It prints out the thing that it's spawning or it's doing so the second one here is Changing the focus of the stack. So if I had multiple windows here, I do mod j and it would switch between the windows so as you notice this is a little Mmm Not that readable. I would say right so we're going to be using another command So let's go ahead and then back into oops. That's not the right one CS that sh And of course, I can't do you see CS that sh there we go All right, so now we want to go back into insert mode and we want to clean that up quite a bit So we're in order to do that. We're going to go through and do We're gonna use the said command. So basically what said is going to do is it's going to search for something and then it's going to replace something so a set is another one of those commands that is Very Multi-purpose you can use it for many different things. It's not as multi-purpose as aock Obviously because there's just ton of stuff that you can do it off But in this case, we're going to be using said in order to do some Global searching and to remove some stuff. So pipe again and then said and then we're going to do single quotes Or inverted commas as the British would say I think so we're going to do search and we're going to search for The comma so if we go back to Seven when we printed this out, we got a whole bunch extra commas. We get this comma We get this comma we get this comma. There's a comma back here somewhere And stuff so we want to get rid of all those So we're going to search for the commas. We're going to replace it with space We're just going to leave that empty and then you want to do that globally okay, and now if we save this and We go to a different workspace and we just zoom in here and we we'd run dot slash csh again CS dot sh. I should mean that's something a little bit easier to say Now we've gone through and gotten rid of all the commas now. There's is still very unreadable So let's go ahead and clear that and we'll run it again here in this. We'll keep this open So I'm actually going to go back here to Ock and add some stuff. So if in between these we put in some spaces and Actually, what I'm going to do is add some dash dash dash here and delete those spaces and then we'll add a space in Between here, okay, and then this already will clean this up quite a bit So if we go back to this workspace and run this again, we now we have at least some spaces. So we're getting there So if we go back to this workspace, we can go to the end of the line here And for whatever reason Google decided it was going to listen to me at that point. I didn't say anything about Google Okay, and then we're going to pipe again and we're gonna do some more said so this next one We're gonna want to get rid of all of the If we go back here, I want to get rid of all the xk underscores because we don't really need those things So we just want mod key y to know that we're toggling the scratch pads if I had my key y I get a scratch pad. I don't need my key xk underscore, right? So we just go back here and be said and then inverted commas and we're going to do search for xk underscore and Then we're going to replace that with nothing Okay, and we're gonna do that globally. Okay, that's how said works. Okay, so if we save this again And we go back here to 8 and we clear this out and we run it the Script again now we've gotten rid of all the xk underscores. We just mod key left and Then it tells you it's focusing the monitor, right? So that's the way that works Okay, so the next thing we want to get rid of is Some of the ampers stands so I don't know why I wanted to get rid of this because I actually don't oh I do see something like these what these ampers stands up here. We don't really need that Okay So we're gonna get rid of that next and We're gonna do two in a row two things right in a row here So we're gonna do said inverted commas s. So we're gonna search for ampers stands We're going to replace them with nothing and we're gonna do that globally. Okay, and then we're gonna do another one said inverted commas and this one we're going to actually change something so if we go back here to the Script output. We'll see the shift mask thing here. We want to replace This pipe shift mask with just plus to shift So we're gonna go back to the thing here. We're going to do we're in a search for pipe Shift man, I think that's all No, it's It's done this way shift Mask, okay, and then we're gonna replace that with Plus I Think we have to leave a space plus shift Okay, and then we're going to do that globally Okay, now if we save this again and go back here and we'll clear this and we'll run the script again So now whenever we have a mod Plus shift key. It just says mod plus shift So now I want to change everything that says mod key just to use the word mod so again, I mean this is getting very repetitious now, but We're just going to carry on we're going to do said Now if you're a script or if you're somebody who's really good at scripting I'm sure there's more a more efficient way of doing this. I'm a hundred percent sure about this I am not a professional scripter. I'm just not I'm very much a noob. So I Know this is probably terrible syntax, but I don't care. It's just the way it's gonna do so inverted commas we want to search globally for mod key and replace that with mod and And we want to do that globally Okay, and then we also want to do the same thing for control So that we did for shift. So if we do pipe said inverted commas, we're gonna search for Control mask, which we should see here somewhere. Let's see if I can like start right here Oh, we're gonna need to do the pipe as well. So we go back here and do pipe Control mask and then we want to replace that with space plus CTRL and Then we want to do that globally. Okay We're getting there So we go back here clear this and run it again Now we have even more stuff cleaned up We need to add a space between these things here. So that that's gonna be take place in the awk I think I deleted those spaces and said I didn't need them, but I do actually need them so let's go back to and add those we also want to go through and Erase this last bracket here some that some of these have so we want to get rid of that And then we want to go through and put this in a column to make it even better So let's go through. Let's go back here and we wanted to go through and add some spaces here to the awk space here and a space there and then we'll go back here to the end and we want to pipe said inverted commas, I'm just gonna use inverted commas because it's fun Better than saying apostrophe apostrophe, whatever and we want to do search globally for this bracket We replace it with nothing and we want to do it globally Okay, now we're gonna write this Actually before we do this, I'm gonna go ahead and just pipe into column Now column is a really cool very unused Command it's basically going to format this into Columns, so it does exactly what it says on the tin as they say I'm turning British. I've been reading Harry Potter again. So everything has been British for me. So anyways, it doesn't matter. So we're gonna go back to this workspace here clear this out and run the command again And that looks so much better, right? So this is what this the script looks like now if you've noticed we have some problems here So first of all, we have some stuff over here. That's just not showing up properly. So I don't actually remember What this is but basically what this does means is that we use the command said to filter out something that we shouldn't have So we'll have to fix that And it's also not picking up all the key binding. So if we actually go back to our configuration file here We'll see some things here that are a little bit different. So alright So what ended up happening is those numbers that we showed here? Don't have mod in front of them at all. These things here aren't actually key bindings They're the tag keys Okay, they don't use the word mod at all, but we still picked it up because they use The the xk underscore thing that we searched for so we're gonna have to fix that what I'm thinking in order to get rid of those things is To change what we're grepping out because I think if we change the grep to Just mod key because I think all of our key bindings have mod key in some form or fashion I don't have anything here. That's not mod key So if we go back here to the script and back to the beginning of the script and we changed this here To mod key I'm wondering what this will do So we'll go back to a we'll we'll clear that out and we'll run it again Yeah, that's much better Unfortunately, it also gives us these things here, which we don't need because those are mouse buttons. I believe So we need to filter those out as well We'll also notice that we need to add when we change the mod Because I'd like to add a plus sign in between these two. So it's just oh, maybe we don't need to do that It's okay, but I have a mod here with a plus sign. So if we go back to the key the script here and We change. Let's see where this is at so first we need to Get rid of this plus here because otherwise we'll end up with two pluses and we change this here to space plus And I think we need to add another space now We'll leave this yeah, we'll add another space just in case we always remove it afterwards and we want to remove the plus here as well Okay, so if we save this now whoops and We go back to the script and we clear this out and run it again That's better. Yeah, and we can get rid of that space. There's an extra space there There's just one here that actually could probably use another Shift because I have mod control shift to actually toggle the tag. I don't actually ever use that key money I don't think But it doesn't matter. We're trying to perfect this damn it So we can get rid of that space and then we can start working on filtering out those last parts there Which is going to be a little bit more interesting So what we need to do is actually add a plus after shifting control. So if we go back here and do This here and do plus after this and we remove The space after this I believe is what I said in years to remove Yes, there's because there's a space up there at dollar sign 3 Okay, and then we can add a plus after the end of this and a space and That will take care some of those stragglers there at the end They didn't have pluses so if we run this again now we have some pluses here So my plus control plus shift plus key Yeah, that works out. Well, okay Now Nick said now we have to go through and get rid of these last parts here My foam is falling that stayed up there a long time like a whole day Scared a crap out of me, too Double-sided tape apparently not so sticky Okay Anything else gonna fall on my head at least it's foam. It's not gonna hurt me not that there's much up there to hurt. Anyways, empty brain Okay All right I'm less likely now to actually figure this out because I don't remember where it was. Okay We need to remove these things I'm sure there's a command or something that I could use to do it. Let me think about it a few moments later Okay, so I think I've got it so if we go back here to the beginning and we change this back to xk underscore Xk underscore and then we go here before the awk and do another grep so grep and Then we want to do mod key Okay, and it's going to grep the same thing because it should work We're gonna try this out. I don't know why I think this will work, but I think it will work so if we Clear this out and run this again Haza it worked Hot damn that was good Okay, so that is the script now like I said depending on what window manager you're in This is going to be a lot harder because if the key bindings you have Don't have commonalities like xk underscore or mod key or super or whatever You're gonna have more greps than what I had so for like I said if you remember back when I was looking at my sxhkd file Every one of those bindings was on a separate line So that was going to be a big pain in the butt So I don't know how you'd go about doing this with an xxk with an sxhkd file It'd be a little bit quite a bit harder if not impossible to begin with It might just be better to if you in that case if we clear this out Let's just say I wanted to to add All right, so I have the script So and I use sxhkd so for here And we go to the end we could also go through and cat dollar sign home Slash dot dwm slash sxhkd slash sxhk drc So and then we want to also pipe that into I don't know if piping this into column would work But we're gonna try because we want it to look as pretty as possible So if we go up here to eight and run this thing again Yeah, that didn't quite work out the way we wanted it to so piping it into column didn't work Why it didn't work has something to do with the way column probably works But this what does it at least get you Those things so The reason why you can't use cat for the Your main configuration file is because that would just print out what cat does is it just prints out everything that's in the file and And that works for the sxhkd thing because all it's in that are that configuration file for the sxhkd is key bindings How I'd go through about making that pretty I'm not exactly sure yet I'm not sure why like I said, I'm assuming that that's a limitation of column a few moments later so I've been playing around with this for a little while now off camera and I can't seem to make this any prettier It's still just exporting it like this I'm sure there's a way and I will discover it probably about a half an hour after I stop recording So if I do discover this I'll put it in the comments below and pin the comment But if you're using something like sxhkd, this would be the way you'd go about creating a cheap Cheat sheet just cat it out and then put it into a key binding or whatever. So that's the last step now that we have Oops went to the wrong thing again. That was audacity. It records things Now that we have this done and I'm actually just going to delete this last part here Until I figure out how to make that pretty What now that we have that done will save this and what we're going to do is we're going to pseudo CP this into this csh.sh into slash user local Then now this is One of the files that is in my path and what that will allow me to do is run this command from anywhere on the system I don't actually have to be in the directory that the script is located So I'm going to do that and I'm going to enter my password. Okay. Now if I run cs.sh I Don't actually have to do dot slash and I can do that from I can you literally use this script from anywhere now what I can do is if If you're just using plain old DWM, you're not using sx.hkd you can go through and add a Key binding to your sx.hk or your to your DWM a configuration file to bring this up so What I'm going to do is I'm going to put it in my sx.hkd file So I'm going to do that DWM sx.hkd and we'll clear this out so we can actually see And we're going to Vim into sx.hkd RC and we'll go to the bottom here and We'll do Let's see here. We're going to do Control I believe CTRL plus I Don't think I have like it the letter I I can do control I would work Actually control I won't work because that would give me like italics and something so that won't work control alt Plus I would probably work though We'll see and then what we want to do is just tap add some space here. I think I need to remove the space here couple space here and do cs.sh Okay, and we'll write this and We'll reset start sx.hkd, which is done by super escape on my system now if I do control alt I That actually doesn't actually work and I know exactly what I did You actually had to get you can't just run that script without actually going through and doing it in a terminal. So That was that was me being a dumbass you have to tell it what terminal to install so We have to do oh black ritty That'll work dash e cs.sh that should work. I think that will work. I'm Don't think I need any like quotation marks And I don't think so. No that should work. So we go back here to the That should work. All right, let's try again Super escape to restart Sx.hkd alt control I and it closed right away Why did it close right away? Because it runs the script and then it just closes a few moments later Okay, so I've discovered what I need to do. I've done some research and I Had no clue that this would actually, you know have to be done So I've learned something right alongside you. So I'm going to go back through and edit my script so I'm going to edit the script in We'll just do the sx cs.sh here and then we'll copy back over so at the end of this what we want to do is use the command read and Basically or at least the way the literature says it should keep the Terminal that it is opened up in Open when it's done. So if we and then we want to add a couple extra spaces at the end So we'll write this actually write and quit this and then we'll cp cs.sh To slash you you actually ought to do pseudo pseudo do this thing here again and Enter our password. Okay. Now if we do control alt and I Our cheat sheet is there now one of the cool things about using alacrity And that's the reason why I've tried to use alacrity is the alacrity allows you to go through and change the class name of a specific Terminal so if we go back to our sx hkd file But first what we'll do is we'll close this and if we do man alacrity What we should be able to do is somewhere around here is find the Thing here and we can go through and change the the class of alacrity within our DWM or SSHKD thing and what that will allow us to do and I'm not gonna do this on camera because rules are hard and DWM They're very confusing But basically what by using this dash dash class and calling this something like a let's actually I'll just go through and do this and Here at the bottom if we do this dash dash class thing and we do Cs.sh I And actually we'll do CS I think that's was the the syntax. I'd have to go back through and check Okay, so let's go back here to eight we'll do Man alacrity Again Look at the the so it's it was there. Okay, so no quotation marks It's just the new class Period so we'll just do CS CS and that should work and basically what that would allow you to do is go through in your DWM Configuration file and then create a rule for that class. So if we save this I Wasn't gonna do this on camera, but we should actually be able to do it if I could if I'm not I don't know a lot about DWM rules So it's not something that I've learned a lot about because I just I don't use them But I should be able to do this so if I could see into my .config suckless DWM and move them into our config.def.h Actually, apparently I already have this open so we'll abort this and go to the right so we have this open So we go up here to the rules Basically what we want to do is make it so that that our cheat sheet floats And appears in the center. It may not appear in the center if you don't have always centered the patch installed so But we should be able to right here is where our rules are So what we want to do is Copy this one like right here Okay, and we want to change the class to cs Okay, so the cs should be the the class name and The instance would also be cs, but we should be able to change that leave that as null Okay, and then we want to go through And change this to one. Okay, and that should work if i'm If i'm doing this right Actually, that's not the right one That should be still be zero. It should be this one here is floating Should be one, okay So we don't want because zero should be false one should be true if I remember right So save this now I'm not gonna be able to show you this and see if it works because I'd actually have to go through And compile this and log out and log back in because I don't have it set up to actually live refresh dwm but if I've done it right and I think I have every time I go through and hit control alt i To get my cheat sheet that should come up as a floating window kind of like a scratch pad so I will Try that afterwards and I will let you know in the comments below if I've it if it actually succeeded But that is it That was a really long video For what it was it was supposed to be like a 15 minute video and I'm sure I'm going to cut some of this out So it won't actually be an hour long because holy Holy crap. It's like I didn't expect to be an hour. I was injured by foam during this video. It's how long it's been. I mean the the strength of the double-sided tape has Failed completely during this video. That's how long this video has been going on. So thank you for watching If you want to follow me on twitter, you can do so at the linux cast at facebook You can follow me on facebook at linux cast and you can support me on patreon at patreon.com slash linux cast Before I go I'd like to take a moment to thank our current patrons Deva and marcus makelyn donnie's fen merrick camp Mitchell. Thanks everybody for watching. Thank you for your support I'll see you next time