File tree Expand file tree Collapse file tree 2 files changed +18
-14
lines changed Expand file tree Collapse file tree 2 files changed +18
-14
lines changed Original file line number Diff line number Diff line change @@ -6,11 +6,7 @@ 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 is_wsl; then
10
- local battery
11
- battery=$( find /sys/class/power_supply/* /capacity | tail -n1)
12
- cat " $battery "
13
- elif command_exists " pmset" ; then
9
+ if command_exists " pmset" ; then
14
10
pmset -g batt | grep -o " [0-9]\{1,3\}%"
15
11
elif command_exists " acpi" ; then
16
12
acpi -b | grep -m 1 -Eo " [0-9]+%"
@@ -36,6 +32,12 @@ print_battery_percentage() {
36
32
termux-battery-status | jq -r ' .percentage' | awk ' {printf("%d%%", $1)}'
37
33
elif command_exists " apm" ; then
38
34
apm -l
35
+ elif command_exists " termux-battery-status" " jq" ; then
36
+ termux-battery-status | jq -er ' "\(.percentage)%"'
37
+ elif is_wsl; then
38
+ local battery
39
+ battery=$( find /sys/class/power_supply/* /capacity | tail -n1)
40
+ cat " $battery "
39
41
fi
40
42
}
41
43
Original file line number Diff line number Diff line change @@ -32,25 +32,21 @@ is_wsl() {
32
32
}
33
33
34
34
command_exists () {
35
- local command=" $1 "
36
- type " $command " > /dev/null 2>&1
35
+ local command
36
+ for command ; do
37
+ type " $command " > /dev/null 2>&1 || return $?
38
+ done
37
39
}
38
40
39
41
battery_status () {
40
- if is_wsl; then
41
- local battery
42
- battery=$( find /sys/class/power_supply/* /status | tail -n1)
43
- awk ' {print tolower($0);}' " $battery "
44
- elif command_exists " pmset" ; then
42
+ if command_exists " pmset" ; then
45
43
pmset -g batt | awk -F ' ; *' ' NR==2 { print $2 }'
46
44
elif command_exists " acpi" ; then
47
45
acpi -b | awk ' {gsub(/,/, ""); print tolower($3); exit}'
48
46
elif command_exists " upower" ; then
49
47
local battery
50
48
battery=$( upower -e | grep -E ' battery|DisplayDevice' | tail -n1)
51
49
upower -i $battery | awk ' /state/ {print $2}'
52
- elif command_exists " termux-battery-status" ; then
53
- termux-battery-status | jq -r ' .status' | awk ' {printf("%s%", tolower($1))}'
54
50
elif command_exists " apm" ; then
55
51
local battery
56
52
battery=$( apm -a)
@@ -59,5 +55,11 @@ battery_status() {
59
55
elif [ $battery -eq 1 ]; then
60
56
echo " charging"
61
57
fi
58
+ elif command_exists " termux-battery-status" " jq" ; then
59
+ termux-battery-status | jq -er ' .status | ascii_downcase'
60
+ elif is_wsl; then
61
+ local battery
62
+ battery=$( find /sys/class/power_supply/* /status | tail -n1)
63
+ awk ' {print tolower($0);}' " $battery "
62
64
fi
63
65
}
You can’t perform that action at this time.
0 commit comments