Re: [dwm] Done Before: dwm stat scripts!

From: Kurt H Maier <karmaflux_AT_gmail.com>
Date: Mon, 1 Oct 2007 18:46:24 -0500

I'm not really happy with calling perl in battery.sh, but bc proved to
be enough of a turd that I won't use it. If anyone knows how to cast
floats to int in bash let me know. :V

relevant section of config.h:

{ MODKEY|ShiftMask, XK_p, spawn, \
        "exe=`$HOME/.scripts/battery.sh BAT0 > $HOME/.dwm_status` &&
exec $exe" }, \
{ MODKEY|ShiftMask, XK_i, spawn, \
       "exe=`$HOME/.scripts/get_wifi_info.sh eth1 > $HOME/.dwm_status`
&& exec $exe" }, \
{ MODKEY|ShiftMask, XK_o, spawn, \
       "exe=`$HOME/.scripts/get_date.sh > $HOME/.dwm_status` && exec $exe" }, \
{ MODKEY|ShiftMask, XK_u, spawn, \
        "exe=`$HOME/.scripts/get_cpustuff.sh > $HOME/.dwm_status` &&
exec $exe" }, \

.xinitrc:
[irrelevant stuff snipped]
dwm <> $HOME/.dwm_status &

while true; do
        $HOME/.scripts/get_date.sh > $HOME/.dwm_status
        sleep 60
done

get_cpustuff.sh:

#!/bin/sh

CPU_FREQ=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq |
sed -e "s/0.*//" | sed -e "s/^\([0-1]\)/\1\./" | sed -e
"s/^\([2-9]\)/0\.\1/"`

CPU_TEMP=`awk '/temperature/ { print $2$3 }'
/proc/acpi/thermal_zone/THM0/temperature `

CPU_PERC=`awk '/cpu0/ { printf "%i",
($2+$3+$4+$5+$6+$7+$8+$9+$10)/33329699*100 }' /proc/stat `

echo Processor: $CPU_PERC% of $CPU_FREQ GHz @ $CPU_TEMP

get_date.sh:

#!/bin/sh

date -R | sed -e "s/[:][0-9][0-9] [+-].*$//"

get_wifi_info.sh:

#!/bin/sh

CURRENT_ESSID=`/sbin/iwconfig $1 | grep ESSID | sed -e
"s/$1.*ESSID:[\"o]//" | sed -e "s/[\"\/L].*//" | sed -e "s/\"//g" |
sed -e "s/^ff$/off/" | sed -e "s/.*off.*/off/" `

LINK_QUAL=`/sbin/iwconfig $1 | grep -A5 ESSID | grep Quality | sed -e
"s/.*Quality=//" | sed -e "s/\/.*$//"`

CUR_IP=`/sbin/ifconfig $1 | grep "inet addr" | sed -e "s/.*inet
addr://" | sed -e "s/Bcast.*//"`

echo $1: $CURRENT_ESSID $LINK_QUAL%" " IP: $CUR_IP

battery.sh:#!/bin/sh

BATT_STATE=`awk '/charging state/ { print $3 }' /proc/acpi/battery/$1/state `
BATT_RATE=` awk '/present rate/ { print $3 }' /proc/acpi/battery/$1/state `
BATT_CAPACITY=` awk '/remaining capacity/ { print $3 }'
/proc/acpi/battery/$1/state `
BATT_FULL_CAP=` awk '/last full capacity/ { print $4 }'
/proc/acpi/battery/$1/info `
BATT_PERCENT=$(( BATT_CAPACITY * 100 / BATT_FULL_CAP ))

if [ "$BATT_STATE" = 'discharging' ]; then
    BATT_DISPLAY_PERC=1
    if [ "$BATT_RATE" = 0 ]; then
        unset BATT_REMAIN_HR
        unset BATT_REMAIN_MN
    else
        BATT_REMAIN_HR=`perl -e "print int($BATT_CAPACITY/$BATT_RATE);"`
        BATT_REMAIN_MN=`perl -e "print int(($BATT_CAPACITY/$BATT_RATE*60)%60);"`
    fi
fi

if [ "$BATT_STATE" = 'charging' ]; then
    BATT_DISPLAY_PERC=1
fi

if [ "$BATT_DISPLAY_PERC" = "1" -o "$BATT_PERCENT" = "100" ]; then
    echo -n "Battery: $BATT_STATE - $BATT_PERCENT%"
fi
if [ "$BATT_DISPLAY_PERC" = "0" ]; then
    echo -n "Battery: $BATT_STATE - $BATT_REMAIN_HR h $BATT_REMAIN_MN m"
fi

-- 
# Kurt H Maier
Received on Tue Oct 02 2007 - 01:46:26 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 14:56:43 UTC