Skip to content

Commit 5d2a760

Browse files
committed
Use echo and Append Percentage Symbol
Instead of straightforwardly calling `cat`, I've encased the command in `echo` to enable appending strings. This allows me to add a percentage symbol after calling `cat "$battery"`! This also suppresses any `echo`s for machines without battery (i.e. a desktop environment)
1 parent 5c52d4f commit 5d2a760

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

scripts/battery_percentage.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@ 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
11-
battery=$(find /sys/class/power_supply/*/capacity | tail -n1)
12-
cat "$battery"
10+
local battery=$(find /sys/class/power_supply/*/capacity | tail -n1)
11+
if [ -n "$battery" ]; then
12+
echo $(cat "$battery")%
13+
return
14+
fi
1315
elif command_exists "pmset"; then
1416
pmset -g batt | grep -o "[0-9]\{1,3\}%"
1517
elif command_exists "acpi"; then

0 commit comments

Comments
 (0)