commit b01b7bfdf438a433b11c5c6afea8a226a1a58fda parent 87ca28a38d70b7c71cd1d7c71e88fd4cb0bf8705 Author: Anders Damsgaard <anders@adamsgaard.dk> Date: Thu, 26 Sep 2019 11:38:55 +0200 Fix system status output on OpenBSD Diffstat:
M | .local/bin/sysstatus | | | 65 | ++++++++++++++++++++++++++++++++++++++++++++++------------------- |
1 file changed, 46 insertions(+), 19 deletions(-)
diff --git a/.local/bin/sysstatus b/.local/bin/sysstatus @@ -1,33 +1,60 @@ #!/bin/sh -wlandev="$(find /sys/class/net/ -type l -name 'wlp*' -exec basename {} \;)" battery=BAT0 -mail=$(mailstatus | sed 's/^/ /;s/$/ |/;s/ |//') -music=$(mpc status | sed 1q | sed 's/^volume:.*$//;s/^/ /;s/$/ |/;s/ |//') -keymap=$(setxkbmap -print | sed -n '5s/^.*pc+//;5s/+.*$//;5p') -if type pulsemixer >/dev/null 2>&1; then - vol="$(pulsemixer --get-volume | cut -d' ' -f1)%" +separator="|" + +# mail +printf "%s" "$(mailstatus | sed "s/^/ /;s/\$/ $separator/;s/ |//")" + +# music +printf "%s" "$(mpc status | sed 1q | sed 's/^volume:.*$//;s/^/ /;s/$/ |/;s/ |//')" + +# keymap +printf " %s $separator" "$(setxkbmap -print | sed -n '5s/^.*pc+//;5s/+.*$//;5p')" + +# audio volume +printf " ♪ " +if type mixerctl >/dev/null 2>&1; then + printf "%s" "$(mixerctl outputs.master | sed 's/.*=\([0-9]*\),.*/\1/')%" +elif type amixer >/dev/null 2>&1; then + printf "%s" "$(amixer get Master | grep -o "[0-9]*%\|\[off\]")" +elif type pulsemixer >/dev/null 2>&1; then + printf "%s" "$(pulsemixer --get-volume | cut -d' ' -f1)%" +fi +printf " $separator" + +# cpu +printf " " +if type sensors >/dev/null 2>&1; then + printf "%s " "$(sensors | grep -n 'Core 0:' | awk '{print $3}')" +fi +if [ -f /proc/loadavg ]; then + printf "%s" "$(cut -f 1 -d' ' /proc/loadavg)" else - vol=$(amixer get Master | grep -o "[0-9]*%\|\[off\]") + printf "%s" "$(uptime | cut -f 10 -d' ' | sed 's/,$//')" fi -cputemp=$(sensors | grep -n 'Core 0:' | awk '{print $3}') -cpuload=$(cut -d' ' -f1 /proc/loadavg) if [ -d "/sys/class/power_supply/$battery" ]; then batstatus=$(sed -n 's/Charging/+/;s/Discharging/-/' \ /sys/class/power_supply/${battery}/status | sed 's/Unknown//') batlvl=$(cat /sys/class/power_supply/${battery}/capacity) batremain=$(acpi -b | sed 1q |\ sed -n 's/.*\([0-9][0-9]:[0-9][0-9]\):[0-9][0-9].*$/\1/p') - battery="$(echo "${batstatus}${batlvl}% ${batremain}" | sed 's/ $//')" + printf "%s" "$(echo "${batstatus}${batlvl}% ${batremain}" | sed 's/ $//')" fi -wlanssid=$(iwgetid -r $wlandev) -wlanquality=$(echo \ - "0$(grep $wlandev /proc/net/wireless | awk '{print $3}')/70 * 100" |\ - bc -l | sed 's/\..*$//') -date=$(date +'%F %a %T') +printf " $separator" -status="${mail}${music} ${keymap} | ♪ ${vol} | ${cputemp} ${cpuload}" -[ ! "$battery" = "BAT0" ] && status="${status} | ${battery}" -status="${status} | ${wlanssid} ${wlanquality}% | $date" +# wlan +if type ifconfig >/dev/null 2>&1; then + printf " %s" "$(ifconfig iwn0 | grep join | cut -f 3,8 -d' ')" + printf " $separator" +elif type iwgetid >/dev/null 2>&1; then + wlandev="$(find /sys/class/net/ -type l -name 'wlp*' -exec basename {} \;)" + printf " %s" "$(iwgetid -r $wlandev)" + printf " %s" "$(echo \ + "0$(grep $wlandev /proc/net/wireless | awk '{print $3}')/70 * 100" |\ + bc -l | sed 's/\..*$//')%" + printf " $separator" +fi -printf "%s" "$status" +# date +printf " %s" "$(date +'%F %a %T')"