Page 1 of 1

dwm and rotating info on bar.

Posted: Tue Jan 14, 2014 8:18 am
by DebianJoe
I've been playing with my bounty hunter theme and thought, "You know what would look cool? Changing info on the little dwm bar." So I hacked out this little (very crude, but once it worked I just left it alone) script at the bottom of my .xinitrc.

Code: Select all

KERNEL=$(uname -smr)
while true
do
	VOL=$(amixer get Master | tail -1 | sed 's/.*\[\([0-9]*%\)\].*/\1/')
	LOCALTIME=$(date | sed -e 's/CST//' -e 's/\(.*\)/\L\1/')
	TEMP="$(($(cat /sys/class/thermal/thermal_zone0/temp) / 1000))C"
	if [ $marquis -eq "0" ];then
	    xsetroot -name "temp $TEMP >> $LOCALTIME"
	    marquis=1
	elif [ $marquis -eq "1" ]; then
	    xsetroot -name "vol $VOL >> $LOCALTIME"
	    marquis=2
	elif [ $marquis -eq "2" ]; then
	    xsetroot -name "shell $SHELL >> $LOCALTIME"
	    marquis=3
	elif [ $marquis -eq "3" ]; then
	    xsetroot -name "$KERNEL >> $LOCALTIME"
	    marquis=0
	else
	    xsetroot -name "Your indexer is broken"
	    marquis=0
	fi
	sleep 15s
done &
exec dwm
I'm sure there's great room for improvement, but the concept is there. The sed lines in the date are just because I really like lowercase lettering and know sed better than anything else. I'm sure there are better ways to do that too.

Re: dwm and rotating info on bar.

Posted: Tue Jan 14, 2014 9:03 am
by wuxmedia
cool, I wonder if i could implement that neat xsetroot marquis thing on i3...

I got to use 'tr' in my crappy script, it should perform a upper to lower easy.
humph - but I've just spent 10 mins on how to do using the man page, i going to have googleit now. 8(

Code: Select all

 tr [:upper:] [:lower:]
not saying it's better.
apparently bash v4 lets you do the same thing;
http://www.cyberciti.biz/faq/linux-unix ... uppercase/

Re: dwm and rotating info on bar.

Posted: Tue Jan 14, 2014 9:30 am
by machinebacon
neat! so stuff like ansiweather could be piped in there, too. die, conky, die :D

Re: dwm and rotating info on bar.

Posted: Tue Jan 14, 2014 10:03 am
by DebianJoe
You could put whatever you want in there. If it can be scripted, it can be displayed in this manner.

Re: dwm and rotating info on bar.

Posted: Tue Jan 14, 2014 10:11 am
by machinebacon
yeah, just teasing Sector11 ;)

Re: dwm and rotating info on bar.

Posted: Tue Jan 14, 2014 1:40 pm
by mrneilypops
@DebianJoe
Really cool script!
I might use this in my dwmX distrolette.
It would be cool to 'abuse' (lol) your programming skills and add another couple of gizmos to the list...

One small niggle...when I start dwm I get the message 'your indexer is broken" for 15 seconds and then the script starts fine...
Is it possible to change this?
Why is it there anyway? - I guess I could chop it out of the script...

EDIT: I just noticed that Debian kernel info is not printed out.
Temp,Vol,Shell work.

Re: dwm and rotating info on bar.

Posted: Tue Jan 14, 2014 2:52 pm
by DebianJoe
@neilypops
Sure, feel free to do whatever with it.

I added an awk one-liner to mine to print the GHz from each core as in (cpu 2.2 : 1.6). I'll leave it up to you to figure that one out, it took me a few tries before I got it right. :D

Edit: I declared the KERNEL variable outside of the loop so that it wouldn't poll each time. I think I used a KERNEL=$(uname -smr) above the loop, because it's not like your kernel will be changing while running. My mistake for not including that. I will edit the first post to reflect it.

Re: dwm and rotating info on bar.

Posted: Tue Jan 14, 2014 2:55 pm
by mrneilypops
^Thanks!
What am I missing to get the kernel info printing out?

Re: dwm and rotating info on bar.

Posted: Tue Jan 14, 2014 2:58 pm
by DebianJoe
See the above edit, and the edit to the original. I cut out a needed functional part when I copied to the forum post. Sorry for any confusion there.

Re: dwm and rotating info on bar.

Posted: Tue Jan 14, 2014 3:23 pm
by mrneilypops
^Got it now. Working - Thanks.

Re: dwm and rotating info on bar.

Posted: Sat Jan 18, 2014 10:53 pm
by rust collector
I just found this, so I use it now.
If nothing else, I will have to learn...stuff to make it work as I want it.

Thank you!

Re: dwm and rotating info on bar.

Posted: Sun Jan 19, 2014 6:32 am
by DebianJoe
@rust: Little things like this are as much of a practice at writing "bash one-liners" as they are about getting the output working. Best of luck, and there are some truly brilliant scriptwriters here (not me, I am still a noob) who can help you if you get stuck.

Re: dwm and rotating info on bar.

Posted: Wed Jun 25, 2014 7:52 am
by rhowaldt
looks good DJ!

Re: dwm and rotating info on bar.

Posted: Sat Dec 17, 2016 6:52 pm
by dkeg
*bump*
using dwm now, and remembered this. Happy I was able to remember enough to find it.

Re: dwm and rotating info on bar.

Posted: Sat Dec 17, 2016 8:39 pm
by arnold
It will great great to see some nice dwm scrots from you. I use Joe's idea also.