#!/bin/ksh red="%{F#cd0000}" yellow="%{F#cdcd00}" black="%{F#000000}" wifi_ssid=$(cat </dev/null | grep "inet") net=$(echo "$n" | awk '{print $2}') printf "%s" "${net}" } # TODO check length and make sure we aren't wayy off base wifi() { local w sig ssid w=$(ifconfig wlan 2>/dev/null | grep "ieee80211") if [ $? == 0 ]; then ssid="$(echo "$w" | awk "${wifi_ssid}")" sig="$(echo "$w" | awk "${wifi_sig}")" printf "%s : %s : %s" "${ssid}" "${sig}" "$(net)" else printf "%s" "$(net)" fi } beat() { local b b=$(((($(date +'%s')+3600)%86400)*10/864)) printf "%03d" "${b}" } hz() { local hz hz=$(apm -Pv | \ awk \ '{gsub(/\(/, "", $5); gsub(/\)/, "", $6); print $5 " " $6 " " $4}') printf "%s" "$hz" } mem() { local mem_info mem_info=$(top -n | grep Mem | awk "${mem_fix}") printf "%s" "${mem_info}" } temp() { local TMP # Average all the sensors TMP=$(sysctl hw.sensors | grep temp | \ awk -F= '{print $2}' | \ awk "${temp_avg}") if [ $TMP -ge 85 ]; then printf "\\${red}%2d\\${black}°C" "${TMP}" else printf "%2d°C" "${TMP}" fi } battery() { local BATT BAR BATT_LINE if sysctl -n hw.product | grep -iq pine64; then pct=$(sysctl -n hw.sensors.cwfg0.percent0) pct=${pct%%.*} set -A batt_info 0 $pct 0 0 else set -A batt_info $(apm -almb) fi if [ "${batt_info[0]}" != "4" ]; then BATT=$((${batt_info[1]}/10)) BAR="#" if [ "${batt_info[3]}" == "1" ] ; then BAR="+" fi BATT_LINE="" for i in $(jot 10); do if [ "$i" -le "$BATT" ]; then BATT_LINE="${BATT_LINE}${BAR}" else BATT_LINE="${BATT_LINE}-" fi done if [ $BATT -lt 3 ] && [ "${batt_info[3]}" == "0" ]; then BATT_LINE="${red}${BATT_LINE}${black}" fi if [ $BATT -lt 5 ] && [ "${batt_info[3]}" == "0" ]; then BATT_LINE="${yellow}${BATT_LINE}${black}" fi echo "${batt_info[1]}%" "$BATT_LINE" else echo "AC" fi } mail() { if [ -d ~/Maildir ]; then set -A mail_list $(ls -1 ~/Maildir | egrep -vi "gmail|trash") count=0 for dir in "${mail_list[@]}"; do echo -n "${dir}:" ls -1 ~/Maildir/${dir}/Inbox/new | wc -l | \ awk '{ if ($1 > 0) { printf $1 } else { printf "0" }}' count=$((count+1)) if [ $count -ne ${#mail_list[@]} ]; then echo -n "," fi done fi } vmm() { if pgrep -q vmd; then set -A running_vms $(vmctl status | grep running | awk '{print $NF"("$5")"}') echo -n "VMs: " for vm in "${running_vms[@]}"; do echo -n "${vm} " done else echo -n "" fi } printf "%%{l} %s | %s | %%{A:apm -A:}%%{A2:apm -L:}%%{A3:apm -H:}%s%%{A}%%{A}%%{A} | %s %%{r} %s | %s | %s | %s | @%s " \ "$(battery)" "$(temp)" "$(hz)" "$(mem)" \ "$(vmm)" "$(mail)" "$(wifi)" "$(date '+%Y-%m-%d %H:%M')" "$(beat)"