Show correct percentage and time for charging/discharging (#35)

This closes #34, closes #25.
This commit is contained in:
Martin Beentjes 2016-09-24 21:48:09 +02:00 committed by GitHub
parent 8ff4bec3d7
commit 2e99a09d3a
2 changed files with 2 additions and 6 deletions

View file

@ -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}'

View file

@ -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() {