From 9accbdd9efcb0db17f18f5d1ca3da3f7b08c1b3f Mon Sep 17 00:00:00 2001 From: Joshua Perry Date: Fri, 7 Feb 2014 11:10:43 -0700 Subject: [PATCH] Added OSX battery support --- powerline/segments/common.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/powerline/segments/common.py b/powerline/segments/common.py index b2311f16..68033c4c 100644 --- a/powerline/segments/common.py +++ b/powerline/segments/common.py @@ -1079,6 +1079,13 @@ if os.path.exists('/sys/class/power_supply/BAT0/capacity'): def _get_capacity(): with open('/sys/class/power_supply/BAT0/capacity', 'r') as f: return int(float(f.readline().split()[0])) +elif os.path.exists('/usr/bin/pmset'): + def _get_capacity(): + import re + import subprocess + battery_summary = subprocess.check_output(['pmset', '-g', 'batt']).decode('utf8') + batt_percent = re.search(r'\d+%', battery_summary).group(0) + return int(batt_percent.replace('%', '')) else: def _get_capacity(): raise NotImplementedError