2020-05-06 03:20:19 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2020-05-20 18:34:34 +02:00
|
|
|
######################################################################
|
2020-05-23 15:47:21 +02:00
|
|
|
# @author : swytch (adapted from Luke Smith - lukesmith.xyz)
|
|
|
|
# @file : dwmbar
|
|
|
|
# @license : GPLv3
|
|
|
|
# @created : Wednesday May 20, 2020 18:14:14 CEST
|
2020-05-20 18:34:34 +02:00
|
|
|
#
|
2020-05-23 15:47:21 +02:00
|
|
|
# @description : set the statusbar in `dwm`
|
|
|
|
# @dependencies : `xsetroot`
|
2020-05-20 18:34:34 +02:00
|
|
|
######################################################################
|
2020-05-06 03:20:19 +02:00
|
|
|
|
|
|
|
|
|
|
|
# Handle SIGTRAP signals sent by refbar to update the status bar immediately.
|
|
|
|
trap 'update' 5
|
|
|
|
|
2020-05-25 15:04:16 +02:00
|
|
|
delim=" | " # Set the delimiter character.
|
2020-05-06 03:20:19 +02:00
|
|
|
|
|
|
|
status() { \
|
2020-05-20 17:03:00 +02:00
|
|
|
# Get the volume of ALSA's master volume output.
|
2020-05-06 03:20:19 +02:00
|
|
|
volume="$(pamixer --get-volume)"
|
|
|
|
muted="$(pamixer --get-mute)"
|
|
|
|
|
|
|
|
if [ "$muted" = "true" ]; then
|
2020-05-25 15:04:16 +02:00
|
|
|
printf " muted"
|
2020-05-06 03:20:19 +02:00
|
|
|
else
|
2020-05-25 15:04:16 +02:00
|
|
|
printf " 墳 $volume%%"
|
2020-05-06 03:20:19 +02:00
|
|
|
fi
|
|
|
|
|
2020-05-25 15:04:16 +02:00
|
|
|
printf "$delim"
|
2020-05-06 03:20:19 +02:00
|
|
|
|
|
|
|
# Wifi quality percentage and icon if ethernet is connected.
|
2020-05-25 15:04:16 +02:00
|
|
|
wifi="$(grep "^\s*w" /proc/net/wireless | awk '{ print "索", int($3 * 100 / 70) "%" }')"
|
|
|
|
printf "$wifi"
|
2020-05-06 03:20:19 +02:00
|
|
|
eth="$(cat /sys/class/net/enp0s25/operstate)"
|
|
|
|
if [ "up" = "$eth" ]; then
|
2020-05-25 15:04:16 +02:00
|
|
|
printf " / "
|
2020-05-06 03:20:19 +02:00
|
|
|
fi
|
|
|
|
|
2020-05-25 15:04:16 +02:00
|
|
|
printf "$delim"
|
2020-05-06 03:20:19 +02:00
|
|
|
|
|
|
|
# Will show all batteries with approximate icon for remaining power.
|
|
|
|
# Or show that the computer is plugged to a power source
|
|
|
|
# In any case, show the remaining battery percentage
|
|
|
|
AC_ON="$(cat /sys/class/power_supply/AC/online)"
|
|
|
|
for x in /sys/class/power_supply/BAT?/capacity;
|
|
|
|
do
|
|
|
|
if [ "$AC_ON" = 0 ]; then
|
|
|
|
case "$(cat "$x")" in
|
2020-05-25 15:04:16 +02:00
|
|
|
10[0-9]|101) printf "" ;;
|
|
|
|
100|9[0-9]) printf " $(cat "$x")%%" ;;
|
|
|
|
8[0-9]|7[0-9]) printf " $(cat "$x")%%" ;;
|
|
|
|
6[0-9]|5[0-9]) printf " $(cat "$x")%%" ;;
|
|
|
|
4[0-9]|3[0-9]) printf " $(cat "$x")%%" ;;
|
|
|
|
*) printf " $(cat "$x")%%" ;;
|
2020-05-06 03:20:19 +02:00
|
|
|
esac
|
|
|
|
else
|
2020-05-25 15:04:16 +02:00
|
|
|
printf " $(cat "$x")%%"
|
2020-05-06 03:20:19 +02:00
|
|
|
fi
|
2020-05-25 15:04:16 +02:00
|
|
|
done && printf "$delim"
|
2020-05-06 03:20:19 +02:00
|
|
|
|
|
|
|
# Date and time.
|
|
|
|
date '+%b. %d - %I:%M%p'
|
|
|
|
}
|
|
|
|
|
|
|
|
update() { \
|
|
|
|
# So all that big status function was just a command that quicking gets
|
|
|
|
# what we want to be the statusbar. This xsetroot command is what sets
|
|
|
|
# it. Note that the tr command replaces newlines with spaces. This is
|
|
|
|
# to prevent some weird issues that cause significant slowing of
|
|
|
|
# everything in dwm. Note entirely sure of the cause, but again, the tr
|
|
|
|
# command easily avoids it.
|
|
|
|
xsetroot -name "$(status | tr '\n' ' ')" &
|
|
|
|
wait
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
while :; do
|
|
|
|
update
|
|
|
|
# Sleep for a minute after changing the status bar before updating it
|
|
|
|
# again. We run sleep in the background and use wait until it finishes,
|
|
|
|
# because traps can interrupt wait immediately, but they can't do that
|
|
|
|
# with sleep.
|
|
|
|
sleep 60 &
|
|
|
|
wait
|
|
|
|
done
|