1
0
Fork 0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2024-11-22 05:40:08 +00:00

fix(battery): force battery percentage as integer

This commit is contained in:
Marc Cornellà 2021-10-08 15:42:43 +02:00
parent 9aeb967581
commit 5fb204fa74
No known key found for this signature in database
GPG key ID: 0314585E776A9C1B

View file

@ -153,7 +153,7 @@ elif [[ "$OSTYPE" = linux* ]]; then
# Battery #1 : Unknown, 99.55%
# Battery #2 : Discharging, 49.58%, 01:12:05
# All batteries : 62.60%, 02:03:03
acpitool 2>/dev/null | command awk -F, '
local -i pct=$(acpitool 2>/dev/null | command awk -F, '
/^\s+All batteries/ {
gsub(/[^0-9.]/, "", $1)
pct=$1
@ -164,7 +164,8 @@ elif [[ "$OSTYPE" = linux* ]]; then
pct=$2
}
END { print pct }
'
')
echo $pct
elif (( $+commands[acpi] )); then
# Sample output:
# Battery 0: Discharging, 0%, rate information unavailable
@ -227,7 +228,7 @@ function battery_level_gauge() {
local charging_color=${BATTERY_CHARGING_COLOR:-$color_yellow}
local charging_symbol=${BATTERY_CHARGING_SYMBOL:-'⚡'}
local battery_remaining_percentage=$(battery_pct)
local -i battery_remaining_percentage=$(battery_pct)
local filled empty gauge_color
if [[ $battery_remaining_percentage =~ [0-9]+ ]]; then