 Let's talk in this video about how to set up a DWM status bar You may have read the manual for DWM You should probably know the basics, but I want to talk about how I can figure in mind and how I I usually do it how I I have it update how I have it Refresh whenever something's changed. I might not have the best setup, but it definitely works for me So up here right above my head right here. You'll see that I have my status bar. It has my weather It has precipitation chance daily low daily high It has my volume level it has this little icon that tells me if I'm connected to the internet Has my unread mail battery date time all that kind of stuff Now if you know the first thing about DWM You should probably know that in order to set the status bar You really just use x set root and name and you can basically set it to any kind of any text whatever you want So we can say whatever Okay, so that's gonna change my status bar to that now x set root in case you don't know It's not like a DWM specific command. It's a more general command notice actually my status bar changed back I'll explain why that happened in a second But in general when you use this command you can basically put anything and it isn't just text line you you can put the Output of a command so I could say echo My browser or something like that and that's gonna give you the name of my browser, which is there just surf in tab Okay, so how do I actually how did I create this bar that I have and how does it function now? What you're gonna want to do in DWM is basically create There are different ways of doing it and I again I might not have the best but what I have is a separate script called DWM bar And I have this script start every time I started graphical environment now You can patch DWM to do something like auto start some scripts for you. I think that's totally silly because Um, you know, you can just put it in your xinit file I mean, if you don't know anything about linux or unix or whatever xinit is the uh Or well, I guess it's just linux because it's xorg or whatever But xinit is the file that runs when you start x Or if you log in in a desktop environment, you will have x profile Anyway, I have just this script my bar script start when I start the graphical environment and therefore this So what does the script actually do? That's the important thing now the the important aspect of it once I type it out um Is it's actually a while loop and the while loop is going to continually run and what it does is it it uh sets The status bar equal to the output of this function that I define status and I'll talk about that in a second And basically the output of that is going to be everything you see right above me It's going to be the weather it's going to be the volume It's going to be all that kind of stuff just have different commands to do that Um, I also test to see if the weather is is um recent That's an I'll talk about that in a second and then I have it sleep for one minute. Okay So that basically means uh, it'll update the bar and then it'll wait another minute before it tries to update it again Because if you don't if you don't have it sleep is going to be constantly updating the bar every Possible second and your computer is just going to you know, you'll be using all cores to run your status bar now um You might some questions I get is oh my god This isn't going to work because that means it takes a whole minute for your status bar to update So if you change the volume, you're going to have to wait a minute before it you actually see the changes well As you can see right now It's working for me if I go up and down and the reason that I have that if you want If you want to be able to update your status bar whenever it actually changes you do something like this I have a little script. I have it called ref bar And basically all it is is I have this script run. Let's say I In the specific case of my volume commands when I Press my volume, you know my keyboard shortcut to change my volume I actually have that run two things It runs the command that actually changes the volume and it also runs this script And what this script does is it looks for the instance? This is actually really clumsily written There's probably a more elegant way of doing it But what it basically does is it looks for the instance of sleep Running within the dwm bar script and if it exists it will kill it So that means whenever I so I have assigned again You know all of these uh all my volume change commands to run and after that run refresh bar So every time that I press one of those You will see that the refresh bar command runs and the volume is updated Okay, and that's the same thing for anything else. Let's say I I run my mail sync command And I want my bar to be refreshed afterwards. Well, I can just run that afterwards You know have that in the script that refresh, you know sinks my mail. Okay, so that's how that works So let's actually talk about the the modules in this bar And of course, this is the customizable part that you can do pretty much whatever you want So first off as decoration I have The pipe, you know, you'll see there's a little line between each of the modules and I actually set Set this as a variable. So if I change this, let's say I change it to the and sign or something like that You'll see that everything is now changed to and or something like that. Oh notice also I mean just because you know, I guess I might as well notice whenever I change this file in vim I have vim automatically kill it and refresh it. So I get the updates, but That's just the detail So anyway, let let me talk about the status bar command and you'll see I have a couple different things for example I you don't see it now, but I actually do have a music module and if it isn't active, you know Basically, you just take the output of mpc And you format it in the way you want to show You know artists and title of your song or whatever And it outputs there as well But I don't have that right now. I'm going to skip the the weather command. The weather command is actually For those who don't know I don't know I think this is sort of basic knowledge, but I'm sure there are some people who don't know There's this site called wttr.in and you can just see url it in any time and it's going to give you Basically your weather forecast for your area. Um, so that that's pretty nice But basically what I do for this weather command Is I have this download whenever, you know, every day or whatever It checks to see if I have a weather report for today And if I don't it will download this weather report and then it looks for today's date And it gets the like the highest number, you know for our daily high and the lowest number for the daily low And you know the highest precipitation chance. That's what that actually does and you'll see that You know, it actually is the same. It's a bunch of setting and awking. That's what all this is I'm not going to explain it all but you know that that's what it does Anyway, so Everything else here mind you is just outputting commands. So for example, I have a mixer Just to get the volume command here You I have You know, you can test your wireless connection or your ethernet's Opera state From the command line and I really just have these output. You know, I replace stuff for example If you'll see here, so let me take the example of the ethernet Okay, so if I do this at any point in time sys class net My ethernet name and I cat that out. It's going to tell me if my ethernet is all up or down. Okay, so it's up right now So basically, I just have a said command if it's down. I just delete it I just don't have anything up here there If it's up, it replaces that with a little globe and again, that just signalized signalizes Signifies that I'm connected to the internet, right? So that's the kind of stuff and you'll notice that I'll usually just have The delimiter character printed between these modules just so that it appears there Let's see mutt wizard. So yeah, again, if you have a mutt wizard I actually have a status bar that automatically is compatible with that. It checks to see how many unread mail You have in that in your specific mail location And it outputs them there again putting a little fawn awesome character for a mail thing in front of them Same thing with battery and I actually do have multiple batteries sometimes I sometimes have my laptop plugged up to another battery as well So I did find a pretty elegant way just to get all your battery statuses at once So it just loops through so this little, you know case statement Well, really a for loop loops through all your existing plugged up batteries And for each one it will output a battery symbol You know, which is going to be either like a really full or really not full depending on what kind of capacity you have left So that's what that does and finally the date and time which of course you can change here So the thing to keep in mind is all of this all of the stuff that appears here This again is just one function that I just have run and I set X set root to the output of that function the only other thing worth noting I'm not entirely sure why this is you might someone might be able to I don't know inform me about this But I notice that if you have like new lines, like if I just echo all of this stuff out On multiple lines if I have the function output to multiple lines, you can set your status bar as that But for whatever reason it's just really laggy. I don't really know like when you pull up a window It's going to be really laggy So the thing you want to do is either a instead of using echo use like print f and don't have any new lines in here But I think a more elegant way of doing it is when you actually output your status Just translate all of your new lines into spaces or something like that or just delete them Depending on your setup. So that's one thing that I think might be actually better to do But again, I'm not quite sure why that happens, but I'll just say if you don't do that DWM is super laggy I don't someone could tell me why that that goes on but I'm just saying that that's that's what happens But anyway, that's about it. So again, it's relatively simple again So have this start just have some kind of script like this start with your Graphical environment either in your x profile or x in it have it loop through constantly updating and again I do recommend having a refresh bar command Just so you can you know if you have some kind of change going on You can easily refresh the bar if you have time sensitive changes like volume or something like that But anyway, so that's about it. Hopefully you'll learn something and I will see you guys next time