File tree 3 files changed +16
-3
lines changed
3 files changed +16
-3
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,9 @@ source "$CURRENT_DIR/helpers.sh"
6
6
7
7
print_battery_percentage () {
8
8
# 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
10
12
pmset -g batt | grep -o " [0-9]\{1,3\}%"
11
13
elif command_exists " acpi" ; then
12
14
acpi -b | grep -m 1 -Eo " [0-9]+%"
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ battery_discharging() {
17
17
18
18
battery_charged () {
19
19
local status=" $( battery_status) "
20
- [[ $status =~ (charged) ]]
20
+ [[ $status =~ (charged) || $status =~ (full) ]]
21
21
}
22
22
23
23
Original file line number Diff line number Diff line change @@ -22,13 +22,24 @@ is_chrome() {
22
22
fi
23
23
}
24
24
25
+ is_wsl () {
26
+ version=$( < /proc/version)
27
+ if [[ " $version " == * " Microsoft" * ]]; then
28
+ return 0
29
+ else
30
+ return 1
31
+ fi
32
+ }
33
+
25
34
command_exists () {
26
35
local command=" $1 "
27
36
type " $command " > /dev/null 2>&1
28
37
}
29
38
30
39
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
32
43
pmset -g batt | awk -F ' ; *' ' NR==2 { print $2 }'
33
44
elif command_exists " acpi" ; then
34
45
acpi -b | awk ' {gsub(/,/, ""); print tolower($3); exit}'
You can’t perform that action at this time.
0 commit comments