File tree Expand file tree Collapse file tree 2 files changed +10
-6
lines changed Expand file tree Collapse file tree 2 files changed +10
-6
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 is_wsl; then
9
+ if command_exists " termux-battery-status" " jq" ; then
10
+ termux-battery-status | jq -er ' "\(.percentage)%"'
11
+ elif is_wsl; then
10
12
local battery
11
13
battery=$( find /sys/class/power_supply/* /capacity | tail -n1)
12
14
cat " $battery "
Original file line number Diff line number Diff line change @@ -32,12 +32,16 @@ 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
42
+ if command_exists " termux-battery-status" " jq" ; then
43
+ termux-battery-status | jq -er ' .status | ascii_downcase'
44
+ elif is_wsl; then
41
45
local battery
42
46
battery=$( find /sys/class/power_supply/* /status | tail -n1)
43
47
awk ' {print tolower($0);}' " $battery "
@@ -49,8 +53,6 @@ battery_status() {
49
53
local battery
50
54
battery=$( upower -e | grep -E ' battery|DisplayDevice' | tail -n1)
51
55
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
56
elif command_exists " apm" ; then
55
57
local battery
56
58
battery=$( apm -a)
You can’t perform that action at this time.
0 commit comments