From f20b760644548458705fce26997ed912844eac9c Mon Sep 17 00:00:00 2001 From: Dustin Kirkland Date: Mon, 17 Mar 2014 09:55:26 +0900 Subject: [PATCH] * usr/lib/byobu/battery: LP: #1289157 - Mac OS X battery indicator support --- debian/changelog | 5 +++++ usr/lib/byobu/battery | 25 +++++++++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/debian/changelog b/debian/changelog index e3ffb5eb..0bcdaffd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,5 +1,6 @@ byobu (5.75) unreleased; urgency=medium + [ Dustin Kirkland ] * debian/control: - bump standards * usr/lib/byobu/include/shutil, usr/lib/byobu/release: LP: #1278016 @@ -19,6 +20,10 @@ byobu (5.75) unreleased; urgency=medium - allow byobu-launch to pass arguments through to byobu-launcher - fix up the uninstallation of byobu launcher + [ Kosuke Asami ] + * usr/lib/byobu/battery: LP: #1289157 + - Mac OS X battery indicator support + -- Dustin Kirkland Sun, 16 Mar 2014 12:46:36 -0700 byobu (5.74-0ubuntu1) trusty; urgency=low diff --git a/usr/lib/byobu/battery b/usr/lib/byobu/battery index 85386479..cf4cfadd 100755 --- a/usr/lib/byobu/battery +++ b/usr/lib/byobu/battery @@ -31,6 +31,7 @@ __battery_detail() { __battery() { local bat line present sign state percent full rem color bcolor + # Linux support for bat in $BATTERY /sys/class/power_supply/* /proc/acpi/battery/*; do present=""; full=""; rem=""; state="" case "$bat" in @@ -74,6 +75,30 @@ __battery() { ;; esac done + # Mac OS X support + if $BYOBU_TEST /usr/sbin/ioreg >/dev/null 2>&1; then + # MacOS support + local key + for key in CurrentCapacity MaxCapacity ExternalChargeCapable FullyCharged; do + line=$(/usr/sbin/ioreg -n AppleSmartBattery -w0 | grep $key | sed -e 's/|//g' | awk '{ print $3 }') + case "$key" in + CurrentCapacity) rem="$line";; + MaxCapacity) full="$line";; + ExternalChargeCapable) + if [ "${line}" = "Yes" ]; then + state="charging" + elif [ "${line}" = "No" ]; then + state="discharging" + fi + ;; + FullyCharged) + if [ "${line}" = "Yes" ]; then + state="charged" + fi + ;; + esac + done + fi if [ $rem -ge 0 ] && [ $full -gt 0 ]; then percent=$(((100*$rem)/$full)) if [ "$percent" -lt 33 ]; then