aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuca Matei Pintilie <luca@lucamatei.com>2024-07-11 17:54:58 +0000
committerLuca Matei Pintilie <luca@lucamatei.com>2024-07-11 17:54:58 +0000
commit106067ed048a684da33669eff984bd8b98f554a2 (patch)
tree7ba583219af031bf6b93765206da9dc0e588850d
parent4e7e6a36f87de6dfd99167e2830dbf00ec907f69 (diff)
downloaddotfiles-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-xdwm/.dwm/bar/bar.sh52
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"
;;