Support print_battery_remain() for Linux/WSL (#119)

This commit is contained in:
wzy 2025-12-30 22:57:05 +08:00 committed by GitHub
parent 3a1a711ba1
commit 661aa4d25e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 2 deletions

View file

@ -116,7 +116,11 @@ acpi_battery_remaining_time() {
print_battery_remain() {
if is_wsl; then
echo "?" # currently unsupported on WSL
local charge_full charge_now current_now
charge_full=$(find /sys/class/power_supply/*/charge_full | tail -n1 | xargs cat)
charge_now=$(find /sys/class/power_supply/*/charge_now | tail -n1 | xargs cat)
current_now=$(find /sys/class/power_supply/*/current_now | tail -n1 | xargs cat)
echo $charge_full $charge_now $current_now | awk '{num=($1-$2)/$3; printf "%02d:%02d:%02d", int(num), int(60*num%60), int(3600*num%60)}'
elif command_exists "pmset"; then
pmset_battery_remaining_time
elif command_exists "acpi"; then

View file

@ -24,7 +24,7 @@ is_chrome() {
is_wsl() {
version=$(</proc/version)
if [[ "$version" == *"Microsoft"* || "$version" == *"microsoft"* ]]; then
if [[ "$version" == *"Linux"* || "$version" == *"Microsoft"* || "$version" == *"microsoft"* ]]; then
return 0
else
return 1