mirror of
https://github.com/tmux-plugins/tmux-battery.git
synced 2026-09-10 07:26:19 -04:00
Chromebook Support for battery stat (#22)
* chromebook check by /sys/class/chromeos/cros_ecs By checking the existence of the file `/sys/class/chromeos/cros_ecs` (Chrome OS Embedded Controller), one can determine if the machine is a Chromebook. Every Chromebook using the armv7 and x86 architecture will have this file.
This commit is contained in:
parent
926bfd51fd
commit
fe54f2eb66
|
|
@ -18,15 +18,32 @@ print_battery_remain() {
|
|||
pmset_battery_remaining_time
|
||||
elif command_exists "upower"; then
|
||||
battery=$(upower -e | grep battery | head -1)
|
||||
upower -i $battery | grep remain | awk '{print $4}'
|
||||
if is_chrome; then
|
||||
if battery_discharging; then
|
||||
upower -i $battery | grep 'time to empty' | awk '{printf "- %s %s left", $4, $5}'
|
||||
else
|
||||
upower -i $battery | grep 'time to full' | awk '{printf "- %s %s till full", $4, $5}'
|
||||
fi
|
||||
else
|
||||
upower -i $battery | grep -E '(remain|time to empty)' | awk '{print $(NF-1)}'
|
||||
fi
|
||||
elif command_exists "acpi"; then
|
||||
acpi -b | grep -Eo "[0-9]+:[0-9]+:[0-9]+"
|
||||
fi
|
||||
}
|
||||
|
||||
print_battery_full() {
|
||||
if command_exists "upower"; then
|
||||
battery=$(upower -e | grep battery | head -1)
|
||||
upower -i $battery | grep 'time to full' | awk '{printf "- %s %s till full", $4, $5}'
|
||||
fi
|
||||
}
|
||||
|
||||
main() {
|
||||
if battery_discharging; then
|
||||
print_battery_remain
|
||||
else
|
||||
print_battery_full
|
||||
fi
|
||||
}
|
||||
main
|
||||
|
|
|
|||
|
|
@ -13,6 +13,15 @@ is_osx() {
|
|||
[ $(uname) == "Darwin" ]
|
||||
}
|
||||
|
||||
is_chrome() {
|
||||
chrome="/sys/class/chromeos/cros_ec"
|
||||
if [ -d "$chrome" ]; then
|
||||
return 0
|
||||
else
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
command_exists() {
|
||||
local command="$1"
|
||||
type "$command" >/dev/null 2>&1
|
||||
|
|
|
|||
Loading…
Reference in a new issue