Customizing a Status Bar in dwm (Weather, Audio, Mail, Battery and more)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
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 mine and how I usually do it how I have an update how I have it refresh whenever something's changed I might not have the best setup but it definitely works for me um so up here right above my head right here you'll see that I have my status bar it has my whether 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 XM root and name and you can basically set it to any kind of any text whatever you want so we can say whatever text okay so that's gonna change my status bar to that now exit route 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's just surf in tabbed okay so how do I actually how did I create this bar that I have hat 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 again I might not have the best but what I have is a separate script called DWM bar and I have this grip start every time I start a graphical environment now you can patch DWM to do something like auto start some scripts for you I think that's totally silly because you know you can just put it in your X init file yeah I mean if you don't know anything about Linux or UNIX or whatever X in it is the or well I guess it's just Linux cuz the tech sword or whatever but X in it is the file that runs when you start X or if you log in in a desktop and 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 is this script actually do that's the important thing now the the important aspect of it once I type it out is it's actually a while loop and the while loop is gonna continually run and what it does is it it sets the status bar equal to the output of this function that I defined status and I'll talk about that in a second and basically the output of that is gonna be everything you see right above me it's gonna be the weather it's gonna be the volume it's gonna be all that kind of stuff just have different commands to do that I also test to see if the weather is is recent that's an all talked about in second and then I have it sleep for one minute okay so that basically means it'll update the bar and then it will wait another minute before it tries to update it again because if you do if you don't have it sleep it's gonna be constantly updating the bar every possible second and your computer is just gonna you know you'll be using all cores to run your status bar now if you might some questions I get is oh my god this isn't gonna work because that means it takes a whole minute for your status bar to update so if you change the volume you're gonna have to wait a minute before it you actually see the changes well you as you can see right now that 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 to run let's say I in the specific case of my volume commands when I press my vault you know my keyboard shortcut to change my volume I actually have that run to 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 it if it exists it will kill it so that means whenever so I have assigned again you know all of these 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 after we you know have that in the script that refresh it you know syncs 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 + sign or something like that you'll see that everything is now changed - and or something like that oh and notice also I mean just because you know I guess I might as well notice whenever I change this file in vim I have them automatically kill it and refresh it so I get the updates but that's just the detail so anyway let me talk about the status bar command and you'll see I have a couple different things for example I 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 a you know artist and title of your song or whatever and it outputs there as well but I don't have that right now I'm gonna 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 the site called wtt r dot in I in and you can just see URL it at any time and it's gonna give you basically your weather forecast for your area 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'll will download this weather report and it then it looks for today's date and it gets the like the hi number you know for our daily high in 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 day it's a bunch of setting a knockin that's what all this is I'm not gonna 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-- upper 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 sysclass net my Ethernet name and I cat that out it's gonna 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 and just so that it appears there let's see multi-search so yeah again if you have mutt wizard you 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 fallen out some 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 to you know which is gonna be either like really full or really not full depending on what kind 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 accept root to the output of that function the only other thing worth noting I'm not entirely sure why this is Yuma someone might be able to I don't know inform me about this but I noticed 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 it for whatever reason it's just really laggy I don't really know like when you pull up a window it's gonna be really laggy so the thing you want to do is either a instead of using echo use like printf 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 Bay 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 i someone could tell me why that that goes on but i'm just saying that that's and that's what happens but anyway that's about it so again it's relatively simple again so have this star just have some kind of script like this start with your graphical environment either in your ex 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 count 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 learn something and I will see you guys next time
Info
Channel: Luke Smith
Views: 119,952
Rating: undefined out of 5
Keywords: gnu, linux, tutorial, introduction, unix, philosophy, minimal, minimalism, minimalst, computer, programming, program, i3, i3-gaps, vim, emacs, vi, tex, latex, markdown, git, github, groff, arch, gentoo, distro, distribution, distrobution, ubuntu, fedora, thinkpad, floss, free, open, source, foss, software, dwm, dwmbar, bar, script, xsetroot, name, suckless, weather, report, mail, time, date, volume, alsa, pulseaudio, sed, awk, refresh, i3blocks, signal, kill, sleep, wttr.in, wttr, wego
Id: NuS_JLkQbKc
Channel Id: undefined
Length: 10min 38sec (638 seconds)
Published: Fri Jun 07 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.