195 lines
3.5 KiB
Bash
Executable File
195 lines
3.5 KiB
Bash
Executable File
#!/bin/ksh
|
|
|
|
red="%{F#cd0000}"
|
|
yellow="%{F#cdcd00}"
|
|
black="%{F#000000}"
|
|
|
|
wifi_ssid=$(cat <<EOF
|
|
\$1 ~ "ieee80211" {
|
|
split(\$0, chars, "");
|
|
match(\$0, /join .* chan/);
|
|
ssid = substr(\$0, RSTART + 5, RLENGTH - 10)
|
|
gsub(/\"/, "", ssid)
|
|
print ssid
|
|
}
|
|
EOF
|
|
)
|
|
wifi_sig=$(cat <<EOF
|
|
\$1 ~ "ieee80211" {
|
|
split(\$0, chars, "");
|
|
match(\$0, /[0-9]+%/);
|
|
val=substr(\$0, RSTART, RLENGTH)
|
|
if (val == "") {
|
|
printf \$(NF - 9)
|
|
} else {
|
|
printf "%3d%%", val
|
|
}
|
|
}
|
|
EOF
|
|
)
|
|
|
|
mem_fix=$(cat <<EOF
|
|
{
|
|
split(\$3, real, "/")
|
|
print "Mem: U: " real[2] " F: " \$6 " C: " \$8
|
|
}
|
|
EOF
|
|
)
|
|
|
|
temp_avg=$(cat <<EOF
|
|
BEGIN {
|
|
count=0
|
|
sum=0
|
|
}
|
|
{
|
|
count++
|
|
sum += \$1
|
|
}
|
|
END {
|
|
b = sum / count
|
|
printf("%d",b+=b<0?0:0.9)
|
|
}
|
|
EOF
|
|
)
|
|
|
|
net() {
|
|
local n net
|
|
n=$(ifconfig egress 2>/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
|
|
}
|
|
|
|
now_playing() {
|
|
local NP
|
|
NP="-"
|
|
|
|
# MPD
|
|
if pgrep -q mpd; then
|
|
NP="$(mpc -f '%name%%artist% - %title%' | head -n1)"
|
|
fi
|
|
|
|
# Pianobar
|
|
if pgrep -q pianobar; then
|
|
NP="pianobar"
|
|
fi
|
|
|
|
printf "%s" "${NP}"
|
|
}
|
|
|
|
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 | %s %%{r} | %s | %s | %s | %s | %s | @%s " \
|
|
"$(battery)" "$(temp)" "$(hz)" "$(mem)" "$(weather -color)" \
|
|
"$(now_playing)" "$(vmm)" "$(mail)" "$(wifi)" "$(date '+%Y-%m-%d %H:%M')" "$(beat)"
|