File tree 2 files changed +11
-6
lines changed
2 files changed +11
-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 -r .percentage
11
+ elif is_wsl; then
10
12
if [ -e /sys/class/power_supply/* /capacity ]; then
11
13
echo $( cat $( find /sys/class/power_supply/* /capacity | tail -n1) ) %
12
14
fi
Original file line number Diff line number Diff line change @@ -32,12 +32,17 @@ 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
38
+ (( $? == 0 )) || return $?
39
+ done
37
40
}
38
41
39
42
battery_status () {
40
- if is_wsl; then
43
+ if command_exists " termux-battery-status" " jq" ; then
44
+ termux-battery-status | jq -r ' .status' | awk ' {printf("%s%", tolower($1))}'
45
+ elif is_wsl; then
41
46
if [ -e /sys/class/power_supply/* /status ]; then
42
47
local battery
43
48
battery=$( find /sys/class/power_supply/* /status | tail -n1)
@@ -51,8 +56,6 @@ battery_status() {
51
56
local battery
52
57
battery=$( upower -e | grep -E ' battery|DisplayDevice' | tail -n1)
53
58
upower -i $battery | awk ' /state/ {print $2}'
54
- elif command_exists " termux-battery-status" ; then
55
- termux-battery-status | jq -r ' .status' | awk ' {printf("%s%", tolower($1))}'
56
59
elif command_exists " apm" ; then
57
60
local battery
58
61
battery=$( apm -a)
You can’t perform that action at this time.
0 commit comments