mirror of
https://github.com/tmux-plugins/tmux-battery.git
synced 2026-09-10 07:26:19 -04:00
Show correct percentage and time for charging/discharging (#35)
This closes #34, closes #25.
This commit is contained in:
parent
8ff4bec3d7
commit
2e99a09d3a
|
|
@ -7,7 +7,7 @@ source "$CURRENT_DIR/helpers.sh"
|
|||
print_battery_percentage() {
|
||||
# percentage displayed in the 2nd field of the 2nd row
|
||||
if command_exists "pmset"; then
|
||||
pmset -g batt | awk 'NR==2 { gsub(/;/,""); print $2 }'
|
||||
pmset -g batt | grep -o "[0-9]\{1,3\}%"
|
||||
elif command_exists "upower"; then
|
||||
for battery in $(upower -e | grep battery); do
|
||||
upower -i $battery | grep percentage | awk '{print $2}'
|
||||
|
|
|
|||
|
|
@ -10,11 +10,7 @@ battery_discharging() {
|
|||
}
|
||||
|
||||
pmset_battery_remaining_time() {
|
||||
local output="$(pmset -g batt | awk 'NR==2 { gsub(/;/,""); print $4 }')"
|
||||
# output has to match format "10:42"
|
||||
if [[ "$output" =~ ([[:digit:]]{1,2}:[[:digit:]]{2}) ]]; then
|
||||
printf "$output"
|
||||
fi
|
||||
pmset -g batt | grep -o '[0-9]\{1,2\}:[0-9]\{1,2\}'
|
||||
}
|
||||
|
||||
print_battery_remain() {
|
||||
|
|
|
|||
Loading…
Reference in a new issue