Use consistent bash5 style for conditionals and quoting

This commit is contained in:
David Heinemeier Hansson
2026-02-21 10:18:47 +01:00
parent d2acf3b6ba
commit 7514ae7dcf
113 changed files with 289 additions and 287 deletions
+6 -6
View File
@@ -8,13 +8,13 @@ direction="${1:-up}"
# Find keyboard backlight device (look for *kbd_backlight* pattern in leds class).
device=""
for candidate in /sys/class/leds/*kbd_backlight*; do
if [[ -e "$candidate" ]]; then
if [[ -e $candidate ]]; then
device="$(basename "$candidate")"
break
fi
done
if [[ -z "$device" ]]; then
if [[ -z $device ]]; then
echo "No keyboard backlight device found" >&2
exit 1
fi
@@ -24,14 +24,14 @@ max_brightness="$(brightnessctl -d "$device" max)"
current_brightness="$(brightnessctl -d "$device" get)"
# Calculate step as one unit (keyboards typically have discrete levels like 0-3).
if [[ "$direction" == "cycle" ]]; then
if [[ $direction == "cycle" ]]; then
new_brightness=$(( (current_brightness + 1) % (max_brightness + 1) ))
elif [[ "$direction" == "up" ]]; then
elif [[ $direction == "up" ]]; then
new_brightness=$((current_brightness + 1))
[[ $new_brightness -gt $max_brightness ]] && new_brightness=$max_brightness
(( new_brightness > max_brightness )) && new_brightness=$max_brightness
else
new_brightness=$((current_brightness - 1))
[[ $new_brightness -lt 0 ]] && new_brightness=0
(( new_brightness < 0 )) && new_brightness=0
fi
# Set the new brightness.