diff options
author | Luca Matei Pintilie <luca@lucamatei.com> | 2024-07-11 17:54:58 +0000 |
---|---|---|
committer | Luca Matei Pintilie <luca@lucamatei.com> | 2024-07-11 17:54:58 +0000 |
commit | 106067ed048a684da33669eff984bd8b98f554a2 (patch) | |
tree | 7ba583219af031bf6b93765206da9dc0e588850d /dwm | |
parent | 4e7e6a36f87de6dfd99167e2830dbf00ec907f69 (diff) | |
download | dotfiles-106067ed048a684da33669eff984bd8b98f554a2.tar dotfiles-106067ed048a684da33669eff984bd8b98f554a2.tar.gz dotfiles-106067ed048a684da33669eff984bd8b98f554a2.tar.bz2 dotfiles-106067ed048a684da33669eff984bd8b98f554a2.tar.lz dotfiles-106067ed048a684da33669eff984bd8b98f554a2.tar.xz dotfiles-106067ed048a684da33669eff984bd8b98f554a2.tar.zst dotfiles-106067ed048a684da33669eff984bd8b98f554a2.zip |
dwm(bar): silence errors a bit
Diffstat (limited to '')
-rwxr-xr-x | dwm/.dwm/bar/bar.sh | 52 |
1 files changed, 36 insertions, 16 deletions
diff --git a/dwm/.dwm/bar/bar.sh b/dwm/.dwm/bar/bar.sh index 65eb35e..346a583 100755 --- a/dwm/.dwm/bar/bar.sh +++ b/dwm/.dwm/bar/bar.sh @@ -12,7 +12,7 @@ BASEDIR=$(dirname "$SYMLINKDIR") . $BASEDIR/themes/dracula cpu() { - cpu_val=$(grep -o "^[^ ]*" /proc/loadavg) + cpu_val="$(grep -o "^[^ ]*" /proc/loadavg)" printf "^c$black^ ^b$green^ CPU" printf "^c$white^ ^b$grey^ $cpu_val" @@ -31,22 +31,42 @@ pkg_updates() { } battery() { - get_capacity="$(cat /sys/class/power_supply/BAT0/capacity)" - get_status="$(cat /sys/class/power_supply/BAT0/status)" - case $get_status in - Discharging) - printf "^c$blue^ 🔋 $get_capacity" - ;; - *) - printf "^c$blue^ $get_capacity" - ;; - esac + capacity_path="/sys/class/power_supply/BAT0/capacity" + status_path="/sys/class/power_supply/BAT0/status" + + if [ -f "${capacity_path}" ] + then + get_capacity="$(cat /sys/class/power_supply/BAT0/capacity)" + fi + if [ -f "${status_path}" ] + then + get_status="$(cat /sys/class/power_supply/BAT0/status)" + fi + + case "$get_status" in + Discharging) + printf "^c$blue^ 🔋 $get_capacity" + ;; + *) + printf "^c$blue^ $get_capacity" + ;; + esac } brightness() { - brightness="$(cat /sys/class/backlight/*/brightness)" - brightness_max="$(cat /sys/class/backlight/*/max_brightness)" - level=$(echo "scale=2; $brightness / $brightness_max * 100" | bc) + brightness_path=/sys/class/backlight/*/brightness + brightness_max_path=/sys/class/backlight/*/max_brightness + + if [ -f "${brightness_path}" ] + then + brightness="$(cat $brightness_path)" + fi + + if [ -f "${brightness_max_path}" ] + then + brightness_max="$(cat /sys/class/backlight/*/max_brightness)" + fi + level=$(echo "scale=2; $brightness / $brightness_max * 100" | bc) printf "^c$red^ " printf "^c$red^%.0f\n" $level @@ -72,7 +92,7 @@ clock() { volume() { pactl_output="$(pactl list sinks )" is_mute="$(echo "$pactl_output" | grep Mute | grep -oE "yes|no")" - if [ $is_mute = "yes" ] + if [ "$is_mute" = "yes" ] then printf "^c$red^ 🔇 mute" else @@ -83,7 +103,7 @@ volume() { keyboard() { keyboard_bits=$(xset -q | grep -A 0 'LED' | cut -c59-67) - case $keyboard_bits in + case "$keyboard_bits" in 00000000) printf "^c$red^ ⌨️ en" ;; |