Skip to content

Commit 95a6843

Browse files
committed
Check Battery Existence before Calling and Printing Content
This ensures that the script does not return errors when operating in environments without batteries, as if there are no battery-related files in the target directory, the script now stops from accessing the files to begin with.
1 parent 5d2a760 commit 95a6843

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

scripts/battery_percentage.sh

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@ source "$CURRENT_DIR/helpers.sh"
77
print_battery_percentage() {
88
# percentage displayed in the 2nd field of the 2nd row
99
if is_wsl; then
10-
local battery=$(find /sys/class/power_supply/*/capacity | tail -n1)
11-
if [ -n "$battery" ]; then
12-
echo $(cat "$battery")%
13-
return
10+
if [ -e /sys/class/power_supply/*/capacity ]; then
11+
echo $(cat $(find /sys/class/power_supply/*/capacity | tail -n1))%
1412
fi
1513
elif command_exists "pmset"; then
1614
pmset -g batt | grep -o "[0-9]\{1,3\}%"

0 commit comments

Comments
 (0)