diff --git a/scripts/battery_icon_charge.sh b/scripts/battery_icon_charge.sh index 8bdd568..1dff148 100755 --- a/scripts/battery_icon_charge.sh +++ b/scripts/battery_icon_charge.sh @@ -38,7 +38,7 @@ get_icon_charge_settings() { print_icon_charge() { percentage=$($CURRENT_DIR/battery_percentage.sh | sed -e 's/%//') - if [ $percentage -ge 95 -o "$percentage" == "" ]; then + if [[ $percentage -ge 95 || -z "$percentage" ]]; then # if percentage is empty, assume it's a desktop printf "$icon_charge_tier8" elif [ $percentage -ge 80 ]; then diff --git a/scripts/battery_icon_status.sh b/scripts/battery_icon_status.sh index e1873fb..81fb037 100755 --- a/scripts/battery_icon_status.sh +++ b/scripts/battery_icon_status.sh @@ -39,7 +39,10 @@ get_icon_status_settings() { print_icon_status() { local status=$1 - if [[ $status =~ (charged) || $status =~ (full) ]]; then + if [[ is_wsl && -z $status ]]; then + # WSL env with no battery -> _probably_ gonna be a desktop! + printf "$icon_status_charged" + elif [[ $status =~ (charged) || $status =~ (full) ]]; then printf "$icon_status_charged" elif [[ $status =~ (^charging) ]]; then printf "$icon_status_charging" diff --git a/scripts/battery_percentage.sh b/scripts/battery_percentage.sh index d5dce55..7f3714e 100755 --- a/scripts/battery_percentage.sh +++ b/scripts/battery_percentage.sh @@ -7,9 +7,9 @@ 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" + if [ -e /sys/class/power_supply/*/capacity ]; then + echo $(cat $(find /sys/class/power_supply/*/capacity | tail -n1))% + fi elif command_exists "pmset"; then pmset -g batt | grep -o "[0-9]\{1,3\}%" elif command_exists "acpi"; then diff --git a/scripts/helpers.sh b/scripts/helpers.sh index 270e688..3957a57 100644 --- a/scripts/helpers.sh +++ b/scripts/helpers.sh @@ -23,7 +23,7 @@ is_chrome() { } is_wsl() { - version=$( /dev/null cat /proc/version) if [[ "$version" == *"Microsoft"* || "$version" == *"microsoft"* ]]; then return 0 else @@ -38,9 +38,11 @@ command_exists() { battery_status() { if is_wsl; then - local battery - battery=$(find /sys/class/power_supply/*/status | tail -n1) - awk '{print tolower($0);}' "$battery" + if [ -e /sys/class/power_supply/*/status ]; then + local battery + battery=$(find /sys/class/power_supply/*/status | tail -n1) + awk '{print tolower($0);}' "$battery" + fi elif command_exists "pmset"; then pmset -g batt | awk -F '; *' 'NR==2 { print $2 }' elif command_exists "acpi"; then