#!/usr/bin/env sh ###################################################################### # @author : swytch (adapted from Luke Smith - lukesmith.xyz) # @file : dwmbar # @license : MIT # @created : Wednesday May 20, 2020 18:14:14 CEST # # @description : set the statusbar in `dwm` # @dependencies : `xsetroot` ###################################################################### # Handle SIGTRAP signals sent by refbar to update the status bar immediately. trap 'update' 5 delim=" | " # Set the delimiter character. 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}')" if [ "$muted" = "off" ]; then printf " 婢 ---" else printf " 墳 %3d%%" $level fi printf "$delim" # Wifi quality percentage and  icon if ethernet is connected. wifi="$(grep "^\s*w" /proc/net/wireless | awk '{ printf int($3 * 100 / 70) }')" [ $wifi -ne 0 ] && printf "索 %3d%%" $wifi || printf "索 ---" eth="$(cat /sys/class/net/enp0s25/operstate)" if [ "up" = "$eth" ]; then printf " / " fi printf "$delim" # 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 -eq 0 ]; then case "$(cat "$x")" in 10[1-9]) printf " %3d%%" ;; 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") ;; esac else printf " %3d%%" $(cat "$x") fi done && printf "$delim" # 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