From 5d2a760802369d7b5b84d071e242664324748483 Mon Sep 17 00:00:00 2001 From: Paul Kim <44695374+thekpaul@users.noreply.github.com> Date: Mon, 24 Apr 2023 15:49:35 +0900 Subject: [PATCH] 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) --- scripts/battery_percentage.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/scripts/battery_percentage.sh b/scripts/battery_percentage.sh index d5dce55..18cbe9d 100755 --- a/scripts/battery_percentage.sh +++ b/scripts/battery_percentage.sh @@ -7,9 +7,11 @@ source "$CURRENT_DIR/helpers.sh" print_battery_percentage() { # percentage displayed in the 2nd field of the 2nd row if is_wsl; then - local battery - battery=$(find /sys/class/power_supply/*/capacity | tail -n1) - cat "$battery" + local battery=$(find /sys/class/power_supply/*/capacity | tail -n1) + if [ -n "$battery" ]; then + echo $(cat "$battery")% + return + fi elif command_exists "pmset"; then pmset -g batt | grep -o "[0-9]\{1,3\}%" elif command_exists "acpi"; then