fix: is_wsl() matches all Linux kernels, not just WSL#123
Open
gavmor wants to merge 1 commit into
Open
Conversation
/proc/version contains "Linux" on every Linux system (e.g. "Linux version 6.17.0-23-generic ..."). The `|| "$version" == *"Linux"*` condition causes is_wsl() to return true on non-WSL hosts, which makes battery_remain.sh take the WSL sysfs code path instead of falling through to upower/acpi. On systems without acpi installed, the WSL path fails with division-by-zero because /sys/class/power_supply/*/charge_full and charge_now don't exist on modern kernels that use energy_full/energy_now instead. Fix: remove the "Linux" check — only "Microsoft"/"microsoft" distinguishes a WSL kernel from a native Linux kernel. 💘 Generated with Crush Assisted-by: DeepSeek V4 Pro via Crush <crush@charm.land>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
is_wsl()inhelpers.shchecks/proc/versionfor"Linux"OR"Microsoft"— but every Linux kernel starts with"Linux version ...", sois_wsl()returnstrueon all Linux hosts, not just WSLbattery_remain.shto take the WSL sysfs code path (readingcharge_full/charge_now) instead of falling through toupower/acpiacpiinstalled, the WSL path silently fails with a division-by-zero error because modern kernels useenergy_full/energy_nowinstead ofcharge_full/charge_now"Microsoft"or"microsoft"— native Linux kernels do not — so removing the"Linux"check correctly distinguishes themTest plan
is_wslreturnstrueon WSL (/proc/versioncontains"Microsoft")is_wslreturnsfalseon native Linux (/proc/versioncontains"Linux"but not"Microsoft")battery_remaincorrectly usesupower(oracpi/pmset/apm) on native Linuxbattery_remainstill uses WSL sysfs path on actual WSL💘 Generated with Crush