From 88400285688f3ea6f6fe0e101174ae69c3ac9847 Mon Sep 17 00:00:00 2001 From: Teddy Date: Sun, 25 May 2014 20:40:33 +0800 Subject: [PATCH] [tmux] Make battery segment use BAT1 if BAT0 was not found --- powerline/segments/common.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/powerline/segments/common.py b/powerline/segments/common.py index 6cfa07a7..d77c4aec 100644 --- a/powerline/segments/common.py +++ b/powerline/segments/common.py @@ -1105,9 +1105,15 @@ class NowPlayingSegment(object): now_playing = NowPlayingSegment() -if os.path.exists('/sys/class/power_supply/BAT0/capacity'): +if os.path.exists('/sys/class/power_supply/'): + _linux_bat_fmt = '/sys/class/power_supply/{0}/capacity' + _linux_bat = 'BAT0' + if not os.path.exists(_linux_bat_fmt.format(_linux_bat)): + _linux_bat = 'BAT1' + if not os.path.exists(_linux_bat_fmt.format(_linux_bat)): + raise NotImplementedError def _get_capacity(pl): - with open('/sys/class/power_supply/BAT0/capacity', 'r') as f: + with open(_linux_bat_fmt.format(_linux_bat), 'r') as f: return int(float(f.readline().split()[0])) elif os.path.exists('/usr/bin/pmset'): def _get_capacity(pl):