You are not logged in.

#1 2011-11-09 15:37:04

stlarch
Member
From: hell
Registered: 2010-12-25
Posts: 1,265

Help with status script dwm

I started messing with my status script for dwm and tried to get as much as possible into one liners (it's really all the functionality I need). Does everything look ok? I think it is, except for the date one. How can I get rid of the seconds?  I use the statuscolors patch and the \x06 and \x05 is for that. Here's the script:

#!/bin/bash
#dwm  status script
#Thanks to jasonwryan, procyon (cpu), seiichiro0185 (temp and hdd), and jandoe (vol)

net(){
net="$("$HOME/bin/speed.sh")"
echo -e "$net"
}

cpu(){
read cpu a b c previdle rest < /proc/stat
prevtotal=$((a+b+c+previdle))
sleep 0.5
read cpu a b c idle rest < /proc/stat
total=$((a+b+c+idle))
cpu=$((100*( (total-prevtotal) - (idle-previdle) ) / (total-prevtotal) ))
echo -e "\x06Ñ\x05$cpu%"
}

mem(){
free -m | awk '/Mem/ {printf("\x06Î\x05%dm", $3)}'
}

temp(){
acpi -t | awk '{printf("\x06ª\x05%d°", $4)}'
}

#Requires hddtemp run as a daemon and netcat
hdd(){
nc 127.0.0.1 7634 2>/dev/null | awk '/dev/ {split($0,hd,"|"); printf("\x05%d°", hd[4])}'
}

vol(){
amixer get Master | awk '$0~/%/{print "\x06í\x05" $4}' | tr -d '[]'
}

bat(){
acpi | awk '{printf("\x06ð\x05%d%", $4)}'
}

dte(){
date | awk '{print "\x06É\x05" $4}'
}

xsetroot -name "$(net)$(cpu)$(mem)$(temp)$(hdd)$(vol)$(bat)$(dte)"

With the date one above, the colors work but I get the seconds. If I use

date +%I:%M | awk '{print}'

I get the output I want but I can't figure out how to work the colors into it. Here's a screenshot. Thanks
tYjc0NQ

Last edited by stlarch (2011-11-09 16:03:52)

Offline

#2 2011-11-09 16:01:41

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Help with status script dwm

Not sure if it helps, but you can skip the awk, as 'date +%I:%M' gets you the same.

Edit:

[karol@black ~]$ LC_ALL=C date | awk '{print $4}'
17:03:13

YMMV if you don't use C locales.Maybe just add 'LC_ALL=C' in front of the date command?

Last edited by karol (2011-11-09 16:06:35)

Offline

#3 2011-11-09 16:08:37

lolilolicon
Member
Registered: 2009-03-05
Posts: 1,722

Re: Help with status script dwm

dte(){
  date +$'\x06É\x05 %I:%M'
}

or, since bash 4.2, you can use the bash builtin printf:

dte() {
  printf '\x06É\x05 %(%I:%M)T' -1
}

This silver ladybug at line 28...

Offline

#4 2011-11-09 16:36:09

stlarch
Member
From: hell
Registered: 2010-12-25
Posts: 1,265

Re: Help with status script dwm

Thank you. ^^^

Offline

Board footer

Powered by FluxBB