This repository has been archived on 2023-03-02. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/.local/bin/dwmbar

87 lines
2.7 KiB
Plaintext
Raw Normal View History

2020-05-06 03:20:19 +02:00
#!/bin/sh
######################################################################
2020-05-23 15:47:21 +02:00
# @author : swytch (adapted from Luke Smith - lukesmith.xyz)
# @file : dwmbar
# @license : MIT
2020-05-23 15:47:21 +02:00
# @created : Wednesday May 20, 2020 18:14:14 CEST
#
2020-05-23 15:47:21 +02:00
# @description : set the statusbar in `dwm`
# @dependencies : `xsetroot`
######################################################################
2020-05-06 03:20:19 +02:00
# Handle SIGTRAP signals sent by refbar to update the status bar immediately.
trap 'update' 5
delim=" | " # Set the delimiter character.
2020-05-06 03:20:19 +02:00
status() { \
# Get the volume of ALSA's master volume output.
level="$(amixer sget Master | awk -F "[][]" ' { printf "%s", $2 }' | awk -F "%" '{printf $1}')"
muted="$(amixer sget Master | awk -F "[][]" '/%/ { printf "%4s", $4 }' | awk '{printf $1}')"
2020-05-06 03:20:19 +02:00
if [ "$muted" = "off" ]; then
printf " 婢 ---"
2020-05-06 03:20:19 +02:00
else
printf " 墳 %3d%%" $level
2020-05-06 03:20:19 +02:00
fi
printf "$delim"
2020-05-06 03:20:19 +02:00
# Wifi quality percentage and  icon if ethernet is connected.
2020-09-02 15:55:25 +02:00
wifi="$(grep "^\s*w" /proc/net/wireless | awk '{ printf int($3 * 100 / 70) }')"
2020-09-03 20:59:23 +02:00
[ $wifi -ne 0 ] && printf "索 %3d%%" $wifi || printf "索 ---"
2020-05-06 03:20:19 +02:00
eth="$(cat /sys/class/net/enp0s25/operstate)"
if [ "up" = "$eth" ]; then
printf " / "
2020-05-06 03:20:19 +02:00
fi
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
2020-09-02 15:55:25 +02:00
if [ $AC_ON -eq 0 ]; then
2020-05-06 03:20:19 +02:00
case "$(cat "$x")" in
10[1-9]) printf " %3d%%" ;;
2020-09-03 20:59:23 +02:00
100|9[0-9]|8[0-9]) printf " %3d%%" $(cat "$x") ;;
7[0-9]|6[0-9]) printf " %3d%%" $(cat "$x") ;;
5[0-9]|4[0-9]) printf " %3d%%" $(cat "$x") ;;
3[0-9]|2[0-9]) printf " %3d%%" $(cat "$x") ;;
*) printf " %3d%%" $(cat "$x") ;;
2020-05-06 03:20:19 +02:00
esac
else
2020-09-02 15:55:25 +02:00
printf " %3d%%" $(cat "$x")
2020-05-06 03:20:19 +02:00
fi
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