#!/bin/rc # ©2006 Kris Maglione # # You may do whatever you like with this script, as long as the # above copyright notice remains. The BSD-Lite disclaimers apply. . 9.rc . wmii.rc rc.ios if(~ $1 -x) fn wmiir { shift; bar=$1 { shift 4 echo $bar $* } } # Set this to the update interval interval=1 # Bar Names bar_cpu=s3cpu bar_io=s4io bars=($bar_cpu $bar_io) # End Configuration fn sigterm sigint { for(i in $bars $bar_time) wmiir remove /bar/$i >[2]/dev/null exit } fn m {hoc -e $"*} for(i in ($bars $bar_time)) wmiir remove /rbar/$i >[2]/dev/null sleep `{m $interval + 1} for (i in $bars) echo -n $wmiinormcol | wmiir create /rbar/$i fn tuple { a=$(wmii$1^col); idx=$2 h = `{echo $a($idx) | tr 'a-f' 'A-F' | sed 's/#//; s/../& /g'} echo 16i $h^p | 9 dc } normbg=`{tuple norm 2} selbg=`{tuple focus 2} normbr=`{tuple norm 3} selbr=`{tuple focus 3} fn col { n=$1; rat=$2; a=$(norm$3); b=$(sel$3); shift 3 m 'int(('$b($n) - $a($n)')' '*' $rat + $a($n)')' } fn cols { val=$1; max=$2; ary=$3; shift 3 if(~ `{m $max - $val} -*) val = $max rat = `{m $val / $max} printf '#%02x%02x%02x' `{col 1 $rat $ary} `{col 2 $rat $ary} `{col 3 $rat $ary} } iostat -c $interval | sed -l 1d | awk 'NR%3 == 0{print;fflush()}' | while(*=`{read}) { us=$1; ni=$2; sy=$3; await=$4; steal=$5; idle=$6 to=`{m 'int('$us + $sy')'} fg = '#000000' bg = `{cols $"to 100 bg} br = `{cols $"to 100 br} *=`{m print 'int('^($to $us $sy $ni)^'),' 0} wmiir xwrite /rbar/$bar_cpu >[2]/dev/null \ $fg $bg $br $1:$2+$3 $4 \ || exit bg = `{cols $await 15 bg} br = `{cols $await 15 br} wmiir xwrite /rbar/$bar_io >[2]/dev/null \ $fg $bg $br $await \ || exit }