#!/bin/sh ## Debug # set -x # These will keep termbar running, but at the cost of leaving processes open # when X dies. Helpful to use when tweaking #trap 'exec $0' HUP # Restart itself #trap 'tput cnorm; exit 1' INT QUIT TERM clock() { CLOCK=$(date '+%a %d %b %H:%M:%S') } workspace_id() { WORKSPACE_ID=$(xprop -root 32c '\t$0' _NET_CURRENT_DESKTOP | cut -f 2) } convert_to_hours() { h=$((${1}/60)) m=$((${1}%60)) printf "%02d:%02d" $h $m } bat() { BAT_PCT=$(apm -l) BAT_TIME=$(convert_to_hours $(apm -m)) # ↯ ⋇ if [ $(sysctl hw.sensors.acpiac0.indicator0 | grep -c On) -eq "1" ]; then AC_STATUS=PWR else AC_STATUS=BAT fi } mem() { MEM=$(top -n | grep Memory | awk {'print $3'}) } cpu() { _CPU_SPEED=$(sysctl hw.cpuspeed | cut -d "=" -f 2) CPU_SPEED=$(bc -l -e scale=1 -e ${_CPU_SPEED}/1000 -e quit | awk '{printf "%.1f", $0}') CPU_TEMP=$(sysctl hw.sensors.cpu0.temp0 | cut -d "=" -f 2 | cut -d "." -f 1) } vol() { _VOL=$(sndioctl output.level | cut -d "=" -f 2) VOL=$(bc -l -e scale=1 -e ${_VOL}*100 -e quit | awk '{printf "%.1f\n", $0}') } while true; do clock workspace_id bat cpu mem vol # Overwrites the input clear #tput cup 1 0 # tput sometimes leaves trailing numbers printf "[${WORKSPACE_ID}] %132.110s CPU: ${CPU_SPEED}Ghz ${CPU_TEMP}C | MEM: ${MEM} | ${AC_STATUS} ${BAT_PCT}%% (${BAT_TIME}) | VOL: ${VOL}%% | ${CLOCK}" sleep 5 done