scripts

shell scripts
git clone git://git.bitsmanent.org/scripts
Log | Files | Refs | README

dwmstatus (1867B)


      1 #!/bin/bash
      2 
      3 getbattery() {
      4 	batpath=/sys/class/power_supply/BAT0/
      5 	for kv in $(cat $batpath/uevent); do export $kv ; done
      6 	enow=$POWER_SUPPLY_ENERGY_NOW
      7 	efull=$POWER_SUPPLY_ENERGY_FULL
      8 	vnow=$POWER_SUPPLY_VOLTAGE_NOW
      9 	acplugged=$POWER_SUPPLY_PRESENT
     10 
     11 	r=$(echo "($enow * 100 / $vnow) * 100 / ($efull * 100 / $vnow)" |bc)
     12 	r="${r}%"
     13 	[ $acplugged -eq 1 ] && r="${r}+" || r="${r}-"
     14 	echo "$r"
     15 }
     16 
     17 getiwlink() {
     18 	s=$(/sbin/iwconfig $1 |head -1 |tr -s " " '.' |cut -d'.' -f3)
     19 	if [ "$s" != "off" ]; then
     20 		r="$(/sbin/iwconfig $1 |grep Quality | sed 's/:\|=/./g' |tr -d [:alpha:],[:space:] |cut -d'.' -f2 |cut -d'/' -f1)%"
     21 	else
     22 		r="off"
     23 	fi
     24 
     25 	echo $r
     26 }
     27 
     28 getdate() {
     29 	date +'%d/%m/%Y %H:%M'
     30 }
     31 
     32 getfreqs() {
     33 	freqs=$(cat /sys/devices/system/cpu/*/cpufreq/scaling_cur_freq)
     34 	ret=""
     35 	for f in $freqs
     36 	do
     37 		f="$(echo "$f / 100000" |bc)"
     38 		f=$(printf "0.%0.2d" $f)
     39 		[ -z "$ret" ] && ret=$f || ret="${ret} $f"
     40 	done
     41 
     42 	echo $ret
     43 }
     44 
     45 gettemp() {
     46 	# XXX handle more sensors
     47 	t=$(cat /sys/class/hwmon/hwmon*/temp1_input |head -1)
     48 	t=$(echo $t / 1000 |bc)
     49 	r=$(printf "%d" $t)
     50 	echo "${r}C"
     51 }
     52 
     53 getalsavol() {
     54 	fds="$(amixer get Master |tail -1  |sed 's/.*\[\([^ ]*\)\] \[\([^ ]*\)\] \[\([^ ]*\)\].*/\1|\2|\3/')"
     55 	pct="$(echo $fds |cut -d'|' -f1)"
     56 	#dcbl="$(echo $fds |cut -d'|' -f2)"
     57 	mute="$(echo $fds |cut -d'|' -f3)"
     58 	[ "$mute" = "on" ] && echo "$pct" || echo "${pct}*"
     59 }
     60 
     61 getpulsevol() {
     62 	fds="$(pactl list sinks |grep -m1 -A9 "^Sink")"
     63 	pct="$(echo "$fds" |tail -1 |cut -d'/' -f2 |tr -d ' ')"
     64 	mute="$(echo "$fds" |tail -2 |head -1 |cut -d: -f2 |tr -d ' ')"
     65 	[ "$mute" = "no" ] && echo "$pct" || echo "${pct}*"
     66 }
     67 
     68 main() {
     69 	battery=$(getbattery)
     70 	iwlink=$(getiwlink wlan0)
     71 	date=$(getdate)
     72 	freqs=$(getfreqs)
     73 	temp=$(gettemp)
     74 	#vol="$(getalsavol)"
     75 	vol="$(getpulsevol)"
     76 	printf "B:%s T:%s W:%s V:%-4s (%s) %s" "$battery" "$temp" "$iwlink" "$vol" "$freqs" "$date"
     77 }
     78 
     79 main "$@"