Skip to content

Commit 742b77c

Browse files
committed
Support print_battery_remain() for Linux/WSL
1 parent 48fae59 commit 742b77c

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

scripts/battery_remain.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,11 @@ acpi_battery_remaining_time() {
115115

116116
print_battery_remain() {
117117
if is_wsl; then
118-
echo "?" # currently unsupported on WSL
118+
local charge_full charge_now current_now
119+
charge_full=$(find /sys/class/power_supply/*/charge_full | tail -n1 | xargs cat)
120+
charge_now=$(find /sys/class/power_supply/*/charge_now | tail -n1 | xargs cat)
121+
current_now=$(find /sys/class/power_supply/*/current_now | tail -n1 | xargs cat)
122+
echo $charge_full $charge_now $current_now | awk '{num=($1-$2)/$3; printf "%02d:%02d:%02d", int(num), int(60*num), int(3600*num%60)}'
119123
elif command_exists "pmset"; then
120124
pmset_battery_remaining_time
121125
elif command_exists "acpi"; then

scripts/helpers.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ is_chrome() {
2424

2525
is_wsl() {
2626
version=$(</proc/version)
27-
if [[ "$version" == *"Microsoft"* || "$version" == *"microsoft"* ]]; then
27+
if [[ "$version" == *"Linux"* || "$version" == *"Microsoft"* || "$version" == *"microsoft"* ]]; then
2828
return 0
2929
else
3030
return 1

0 commit comments

Comments
 (0)