Skip to content

Instantly share code, notes, and snippets.

@webframp
Created April 9, 2012 23:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save webframp/2347244 to your computer and use it in GitHub Desktop.
Save webframp/2347244 to your computer and use it in GitHub Desktop.
#!/bin/zsh
# At the moment, weather, battery bar, time
# TODO:
# mail, cputemp, system load
#
DATE_FORMAT='%A, %Y.%m.%d %H:%M:%S'
GMAIL_CHECK=$HOME/scripts/dzenGmailNotify.py
COC_CHECK=$HOME/scripts/dzgetCOCstats.py
ICONPATH=$HOME/.dzen/icons/dzen_bitmaps
MOCP=/usr/bin/mocp
RHYTHMBOXCLIENT=/usr/bin/rhythmbox-client
INTERVAL=1 #main loop interval
# function calling intervals in seconds
DATEIVAL=1
WEATHERIVAL=1080
VOLIVAL=1
BATTIVAL=1
MUSICIVAL=1
TEMPIVAL=1
MAILVAL=300
COCIVAL=7
fdatetime(){
date +$DATE_FORMAT
}
fgmail(){
$GMAIL_CHECK
}
fvol() {
MUTECOLOR='#506070'
VOLCOLOR='#8cd0d3'
BGCOLOR='#888'
if (amixer sget Master | grep -qF '[off]')
then
color=$MUTECOLOR
icon=${ICONPATH}/vol-hi.xbm
else
color=$VOLCOLOR
icon=${ICONPATH}/vol-mute.xbm
fi
#percentage=$(amixer sget Master | sed -ne 's/^.*Mono: .*\[\([0-9]*\)%\].*$/\1/p')
percentage=$(amixer sget Master | sed -ne 's/^.*Front Left: .*\[\([0-9]*\)%\].*$/\1/p')
eval echo $percentage | gdbar -fg $color -bg $BGCOLOR -h 10 -w 50 -ss 1 -sw 4 -l "^fg(lightblue)^i($icon)^p(2)^fg()"
}
fbattery(){
GW=50 # width of the gauge
GFG='#dbe3a7' # color of the gauge
GH=10 # height of the gauge
GBG='#888' # color of gauge background
STATEFILE='/proc/acpi/battery/BAT0/state' # battery's state file
INFOFILE='/proc/acpi/battery/BAT0/info' # battery's info file
LOWBAT=25 # percentage of battery life marked as low
BAT_FULL=`cat $INFOFILE|grep design|line|cut -d " " -f 11`;
STATUS=`cat $STATEFILE|grep charging|line|cut -d " " -f 12`;
RCAP=`cat $STATEFILE|grep remaining|line|cut -d " " -f 8`;
# calculate remaining power
RPERCT=`expr $RCAP \* 100`;
RPERC=`expr $RPERCT / $BAT_FULL`;
if [ $RPERC -le $LOWBAT ]; then
GFG='#705050'; #low color - red
fi
if [ $STATUS != 'discharging' ]; then
GFG='#dfaf8f'; #charging color - green
else
GFG='#506070'; #normal color - blue
fi
BATBAR=`echo $RPERC | gdbar -h $GH -w $GW -fg $GFG -bg $GBG -ss 1 -sw 4`
#eval echo $RPERC | gdbar -h $GH -w $GW -fg $GFG -bg $GBG -ss 1 -sw 4 #segmented bar
print "^fg(${GFG})^i(${ICONPATH}/battery.xbm)^p(2)^fg()${BATBAR}"
}
fmocp() {
local state
local music
local ptime
state=$(${MOCP} -i | sed -ne 's/^State: //p')
case $state in
PLAY)
music=$(${MOCP} -i | sed -ne 's/^Title: \(.*\)$/\1/p');
[ -z $music ] && music=$(${MOCP} -i | sed -ne 's/File: .*\/\([^ .].*\)$/\1/p')
ptime=$(${MOCP} -i | sed -ne 's/^TimeLeft: //p')
print "^fg(grey70)^i(${ICONPATH}/musicS.xbm)^fg(grey50) (-${ptime}^fg(#dca3a3)^p(3)^i(${ICONPATH}/play.xbm)^fg(grey50))^fg(grey85) ${music}^fg()"
;;
PAUSE)
music=$(${MOCP} -i | sed -ne 's/^Title: \(.*\)$/\1/p');
[ -z $music ] && music=$(${MOCP} -i | sed -ne 's/File: .*\/\([^ .].*\)$/\1/p')
ptime=$(${MOCP} -i | sed -ne 's/^CurrentTime: //p')
print "^fg(grey40)^i(${ICONPATH}/musicS.xbm)^fg(grey60) (${ptime}^fg(#dca3a3)^p(3)^i(${ICONPATH}/pause.xbm)^fg(grey60)) ${music}^fg()"
;;
STOP)
print "^fg(grey40)^i(${ICONPATH}/musicS.xbm)^fg(grey60) (^fg(#dca3a3)^p(2)^r(7x7)^p(2)^fg(grey60))^fg()"
;;
esac
}
fcocstatus() {
local cocrecent
local cocchange
local cocname
#if [ ${${$(LC_ALL=C /sbin/ifconfig eth0)[7]}:gs/addr://} != "BROADCAST" ]; then
if [ `ifconfig eth0 | grep -c ' addr'` -o `ifconfig wlan0 | grep -c ' addr'` ]; then
cocrecent=`w3m -dump http://www.conqueroncontact.com/stats | grep -e 'Most Recent Move'|sed -e 's/Most Recent Move: //' -e 's/second/sec/' -e 's/minute/min/' -e 's/hour/hr/' -e 's/\ ago\ by\ /,/'|cut -d " " -f 11-18`
cocchange=`w3m -dump http://www.conqueroncontact.com/stats | grep -e 'Next Multiplier Change' | sed -e 's/Next Multiplier Change: //' -e 's/second/sec/' -e 's/minute/min/' -e 's/hour/hr/'|cut -d " " -f 5-7`
else
cocrecent='NA'
cocchange='NA'
fi
if [ `echo $cocrecent | grep -c 'swaq|pk'` -eq 0 ]; then
cocline="^i(/home/webframp/.dzen/icons/coc.xpm)^fg(#008dd6) Last: $cocrecent | Change: $cocchange^fg()"
else
cocline="^i(/home/webframp/.dzen/icons/coc.xpm)^fg(#008dd6) Last: ^bg(#e3008d)^fg(black)$cocrecent^fg(#008dd6)^bg() | Change: $cocchange^fg()"
fi
echo $cocline
}
fcocstatuspy(){
$COC_CHECK
}
# Main
DATECOUNTER=$DATEIVAL;WEATHERCOUNTER=$WEATHERIVAL;BATTCOUNTER=$BATTIVAL;MUSICCOUNTER=$MUSICIVAL;VOLCOUNTER=$VOLIVAL;TEMPCOUNTER=$TEMPIVAL;MAILCOUNTER=$MAILVAL;COCCOUNTER=$COCIVAL
while true; do
if [ $DATECOUNTER -ge $DATEIVAL ]; then
PDATE=$(fdatetime)
DATECOUNTER=0
fi
#if [ $MAILCOUNTER -ge $MAILVAL ]; then
# PMAIL=$(fgmail)
#fi
if [ $BATTCOUNTER -ge $BATTIVAL ]; then
PBATTERY=$(fbattery)
BATTCOUNTER=0
fi
#if [ $MUSICCOUNTER -ge $MUSICIVAL ]; then
# # use one or the other not both
# PMUSIC=$(fmocp)
# #PMUSIC=$(frhythmbox)
# MUSICCOUNTER=0
#fi
if [ $VOLCOUNTER -ge $VOLIVAL ]; then
PVOL=$(fvol)
VOLCOUNTER=0
fi
# if [ $COCCOUNTER -ge $COCIVAL ]; then
# PCOC=$(fcocstatuspy)
# COCCOUNTER=0
# fi
# Arrange and print the status line, these contain dzen formatting codes+info
# print "${PCOC}^p(3)^r(3x3)^p(3)${PMUSIC}^p(3)^r(3x3)^p(3)${PVOL}^p(3)^r(3x3)^p(3)${PBATTERY}^p(3)^r(3x3)^p(3)^fg(white)${PDATE}^fg()"
#print "${PMUSIC}^p(3)^r(3x3)^p(3)${PVOL}^p(3)^r(3x3)^p(3)${PBATTERY}^p(3)^r(3x3)^p(3)^fg(#171717)${PDATE}^fg()"
print "^p(3)^r(3x3)^p(3)${PVOL}^p(3)^r(3x3)^p(3)${PBATTERY}^p(3)^r(3x3)^p(3)^fg(#171717)${PDATE}^fg()"
DATECOUNTER=$((DATECOUNTER+1))
WEATHERCOUNTER=$((WEATHERCOUNTER+1))
BATTCOUNTER=$((BATTCOUNTER+1))
#MUSICCOUNTER=$((MUSICCOUNTER+1))
VOLCOUNTER=$((VOLCOUNTER+1))
TEMPCOUNTER=$((TEMPCOUNTER+1))
# COCCOUNTER=$((COCCOUNTER+1))
sleep $INTERVAL
done
# for example, run with:
# dzstatus.sh | dzen2 -ta r -bg '#1c2636' -fg '#99ffff' -fn '-*-terminus-*-*-*-*-12-*-*-*-*-*-*-*'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment