Skip to content

Commit f865b04

Browse files
Added support for WSL (#95)
1 parent f8b8e84 commit f865b04

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

scripts/battery_percentage.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ source "$CURRENT_DIR/helpers.sh"
66

77
print_battery_percentage() {
88
# percentage displayed in the 2nd field of the 2nd row
9-
if command_exists "pmset"; then
9+
if is_wsl; then
10+
cat /sys/class/power_supply/battery/capacity
11+
elif command_exists "pmset"; then
1012
pmset -g batt | grep -o "[0-9]\{1,3\}%"
1113
elif command_exists "acpi"; then
1214
acpi -b | grep -m 1 -Eo "[0-9]+%"

scripts/battery_remain.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ battery_discharging() {
1717

1818
battery_charged() {
1919
local status="$(battery_status)"
20-
[[ $status =~ (charged) ]]
20+
[[ $status =~ (charged) || $status =~ (full) ]]
2121
}
2222

2323

scripts/helpers.sh

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,24 @@ is_chrome() {
2222
fi
2323
}
2424

25+
is_wsl() {
26+
version=$(</proc/version)
27+
if [[ "$version" == *"Microsoft"* ]]; then
28+
return 0
29+
else
30+
return 1
31+
fi
32+
}
33+
2534
command_exists() {
2635
local command="$1"
2736
type "$command" >/dev/null 2>&1
2837
}
2938

3039
battery_status() {
31-
if command_exists "pmset"; then
40+
if is_wsl; then
41+
cat /sys/class/power_supply/battery/status | awk '{print tolower($0);}'
42+
elif command_exists "pmset"; then
3243
pmset -g batt | awk -F '; *' 'NR==2 { print $2 }'
3344
elif command_exists "acpi"; then
3445
acpi -b | awk '{gsub(/,/, ""); print tolower($3); exit}'

0 commit comments

Comments
 (0)