Skip to content

Commit d163ef3

Browse files
rux616martinbeentjes
authored andcommitted
Changed acpi to be preferred over upower (#78)
1 parent 588a941 commit d163ef3

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# Changelog
22

33
### master
4+
- Changed preferred order of utility applications to be `pmset` -> `acpi` -> `upower` -> `termux-battery-status` due to CPU usage issues with `upower` (2019-03-05) (@rux616)
45
- Added `#{battery_status_bg}` feature (@RyanFrantz)
56
- Added multibattery output support for `upower` (@futuro)
67
- Added Chromebook support (@forkjoseph)

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ Enables displaying battery percentage and status icon in tmux status-right.
44

55
## Installation
66

7-
In order to read the battery status, this plugin depends on having either one of the following applications installed:
8-
- pmset
9-
- upower
7+
In order to read the battery status, this plugin depends on having one of the following applications installed:
8+
- pmset (MacOS only)
109
- acpi
10+
- upower
1111
- termux-battery-status
1212

13-
In a normal situation one of these above should be installed on your system by default and thus it would not be necessary to install one of them.
13+
In a normal situation, one of the above should be installed on your system by default and thus it should not be necessary to specifically install one of them. That being said, the `acpi` utility is currently recommended for use over `upower` where possible due to ongoing CPU usage issues.
1414

1515
### Installation with [Tmux Plugin Manager](https://github.com/tmux-plugins/tpm) (recommended)
1616

@@ -133,6 +133,7 @@ twitter if you want to hear about new tmux plugins or feature updates.
133133
- Aleksandar Djurdjic
134134
- Bruno Sutic
135135
- Caleb
136+
- Dan Cassidy
136137
- Diego Ximenes
137138
- Evan N-D
138139
- Jan Ahrens

scripts/battery_percentage.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ print_battery_percentage() {
88
# percentage displayed in the 2nd field of the 2nd row
99
if command_exists "pmset"; then
1010
pmset -g batt | grep -o "[0-9]\{1,3\}%"
11+
elif command_exists "acpi"; then
12+
acpi -b | grep -m 1 -Eo "[0-9]+%"
1113
elif command_exists "upower"; then
1214
# use DisplayDevice if available otherwise battery
1315
local battery=$(upower -e | grep -E 'battery|DisplayDevice'| tail -n1)
@@ -26,8 +28,6 @@ print_battery_percentage() {
2628
if [ -n "$energy" ] && [ -n "$energy_full" ]; then
2729
echo $energy $energy_full | awk '{printf("%d%%", ($1/$2)*100)}'
2830
fi
29-
elif command_exists "acpi"; then
30-
acpi -b | grep -m 1 -Eo "[0-9]+%"
3131
elif command_exists "termux-battery-status"; then
3232
termux-battery-status | jq -r '.percentage' | awk '{printf("%d%%", $1)}'
3333
elif command_exists "apm"; then

scripts/battery_remain.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ acpi_battery_remaining_time() {
112112
print_battery_remain() {
113113
if command_exists "pmset"; then
114114
pmset_battery_remaining_time
115-
elif command_exists "upower"; then
116-
upower_battery_remaining_time
117115
elif command_exists "acpi"; then
118116
acpi_battery_remaining_time
117+
elif command_exists "upower"; then
118+
upower_battery_remaining_time
119119
elif command_exists "apm"; then
120120
apm_battery_remaining_time
121121
fi

scripts/helpers.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ command_exists() {
3030
battery_status() {
3131
if command_exists "pmset"; then
3232
pmset -g batt | awk -F '; *' 'NR==2 { print $2 }'
33+
elif command_exists "acpi"; then
34+
acpi -b | awk '{gsub(/,/, ""); print tolower($3); exit}'
3335
elif command_exists "upower"; then
3436
local battery
3537
battery=$(upower -e | grep -E 'battery|DisplayDevice'| tail -n1)
3638
upower -i $battery | awk '/state/ {print $2}'
37-
elif command_exists "acpi"; then
38-
acpi -b | awk '{gsub(/,/, ""); print tolower($3); exit}'
3939
elif command_exists "termux-battery-status"; then
4040
termux-battery-status | jq -r '.status' | awk '{printf("%s%", tolower($1))}'
4141
elif command_exists "apm"; then

0 commit comments

Comments
 (0)