#!/bin/sh timeout=1 _sys_memory() { vmstat | sed -n '$p' | awk '{print $4}' } _sys_uptime() { uptime | sed -re's/^.*up[ ]+//g' -e's/^([^,]*),.*/\1/g' -e's/^([^ ]+)[ ]*(.).*/\1\2/g' } wireless_info() { _if="$1" printf "WiFi: %s %s %s %s" \ "$_if" \ "$(ifconfig "$_if" | sed -nre 's/^.*nwid ([^ ]+).*$/\1/p')" \ "$(ifconfig "$_if" | sed -nre 's/^.* ([^ ]+dBm) .*$/\1/p')" \ "$(ifconfig "$_if" | sed -nre 's/^.*inet ([^ ]+).*$/\1/p')" } eth_info() { _if="$1" printf "Eth: %s %s %s" \ "$_if" \ "$(ifconfig "$_if" | sed -nre 's/^.*inet ([^ ]+).*$/\1/p')" "$(ifconfig "$_if" | grep -oE '[0-9]+baseT')" } network_info() { default_if="$(netstat -rnf inet | awk '/^default/{print $8}')" if [ -z "$default_if" ] ; then echo "No conn" elif ifconfig "$default_if" | grep -q IEEE802.11 ; then wireless_info "$default_if" else eth_info "$default_if" fi } ac_status() { if [ `apm -a` -eq 1 ] ; then echo "charging" else printf "discharging " if [ `apm -m` != "unknown" ] ; then minutes="$(apm -m)" hours="$(echo "$minutes"/60 | bc)" hours2="$(echo "$minutes"/60 | bc -l)" minutes="$(echo "(${hours2}-${hours})*60" | bc -l )" printf "%d hours, %d minutes left" "$hours" "$minutes" fi fi } cpu_temp() { sysctl hw.sensors.cpu0.temp0 \ | awk -F= '{print $2}' \ | cut -d' ' -f 1 \ | cut -d'.' -f 1 \ | tr -d '\n' printf "c" } cpu_fan() { sysctl hw \ | grep fan \ | awk -F= '{print $2;exit}' \ | cut -d' ' -f 1 \ | tr -d '\n' printf "rpm" } get_status_simple() { echo \ "Volume: $(sndioctl | awk 'BEGIN{FS="="}{if($1 ~ /output.level/){print ($2+0)*100}}') |"\ "Fan: $(cpu_fan) |"\ "Temp: $(cpu_temp) |"\ "Setperf: $(sysctl hw.setperf | awk -F= '{print $2}') |"\ "Batt: $(apm -l) $(ac_status)|"\ "$(network_info) |"\ "$(date '+%m.%d.%Y %H:%M:%S')" } get_status() { echo \ "Volume: $(sndioctl | awk 'BEGIN{FS="="}{if($1 ~ /output.level/){print ($2+0)*100}}')|"\ "Temp: $(sysctl hw.sensors.cpu0.temp0 | awk -F= '{print $2}')|"\ "Fan: $(sysctl hw | grep fan | awk -F= '{print $2;exit}')|"\ "Cpu Freq: $(sysctl hw.cpuspeed | awk -F= '{print $2}')mhz|"\ "Setperf: $(sysctl hw.setperf | awk -F= '{print $2}')|"\ "Batt: $(apm -l) $(ac_status)|"\ "$(network_info) |"\ "Free Mem: $(_sys_memory)|"\ "uptime: $(_sys_uptime)|"\ "$(date '+%m.%d.%Y %H:%M:%S')" } while true ; do xsetroot -name "$(get_status_simple)" sleep "$timeout" done