dotfiles/suckless/config/dwm/statusbar

136 lines
2.8 KiB
Plaintext
Raw Normal View History

#!/bin/sh
# symbola
#export ICON_RCD=🎥
#export ICON_MSC=♬
#export ICON_MTD=🔉
#export ICON_VOL=🔊
#export ICON_NIC=🖧
#export ICON_WFI=📡
#export ICON_MEM=📈
#export ICON_TMP=🌡
#export ICON_PLG=🔌
#export ICON_BAT=🔋
#export ICON_DAT=⏲
# nerdfont
export ICON_RCD='辶'
export ICON_MSC=''
export ICON_MTD='ﱝ '
export ICON_VOL=' '
export ICON_NIC=' '
export ICON_WFI=' '
export ICON_MEM=' '
export ICON_TMP=''
export ICON_PLG=' '
export ICON_BA0=' '
export ICON_BA1=' '
export ICON_BA2=' '
export ICON_BA3=' '
export ICON_BA4=' '
export ICON_DAT=' '
MPD=$(which mpc && echo yes)
statusbar() {
echo -n " "
# recording
[ -f /tmp/recording.pid ] && echo -n "$ICON_RCD "
# mpd
[ -n "$MPD" ] && mpc | awk '
NR == 1 {
SONG = $0
}
NR == 2 {
PLAYING = $1
}
END {
if (PLAYING == "[playing]")
printf "%s %s ", ENVIRON["ICON_MSC"], SONG
}
'
# volume
amixer get Master | awk 'END {
ICO = $NF == "[off]" ? ENVIRON["ICON_MTD"] : ENVIRON["ICON_VOL"]
2020-11-02 02:59:07 +00:00
match($0, / \[([0-9]+%)\] /, m)
VOL = m[1]
printf "%s %s ", ICO, VOL
}'
# network
for NIC in /sys/class/net/e*; do
grep -q 'up' $NIC/operstate && awk '{
printf "%s %s ",ENVIRON["ICON_NIC"],($0 >= 1000 ? $0 / 1000 "G" : $0 "M")
}' $NIC/speed
done
# wifi
awk 'NR > 2 {
printf "%s %i%% ", ENVIRON["ICON_WFI"], $3*100/70
}' /proc/net/wireless
# cpu temperature
awk '{
printf "%s %i°C ", ENVIRON["ICON_TMP"], $0/1000
}' /sys/class/thermal/thermal_zone0/temp
# memory usage
free | awk 'NR == 2 {
printf "%s %i%% ", ENVIRON["ICON_MEM"], $3/$2*100
}'
# battery
if [ -f /sys/class/power_supply/BAT0/capacity ]; then
grep -q '1' /sys/class/power_supply/AC/online && export PLUGGED=yes
awk '{
if (ENVIRON["PLUGGED"] == "yes")
ICON=ENVIRON["ICON_PLG"]
else if ($0 > 90)
ICON=ENVIRON["ICON_BA4"]
else if ($0 > 75)
ICON=ENVIRON["ICON_BA3"]
else if ($0 > 50)
ICON=ENVIRON["ICON_BA2"]
else if ($0 > 25)
ICON=ENVIRON["ICON_BA1"]
else
ICON=ENVIRON["ICON_BA0"]
printf "%s %s%% ", ICON, $0
}' /sys/class/power_supply/BAT0/capacity
fi
# datetime
echo -n "$ICON_DAT $(date +'%m-%d %H:%M %a') "
}
start() {
while :; do
! pgrep slock 1>/dev/null && xsetroot -name "$(statusbar)"
sleep 1
done
}
restart() {
2020-10-31 03:55:05 +00:00
FP=$(readlink -f $0)
pkill -f "$FP loop"
$FP loop &
}
2020-11-02 13:46:53 +00:00
case "$1" in
loop)
start
;;
dryrun)
statusbar
;;
*)
restart
;;
esac