From e7846f5e68002de55112f1d00ea62e8fa70f6251 Mon Sep 17 00:00:00 2001 From: Dalton Barreto Date: Wed, 23 Nov 2011 12:21:55 -0200 Subject: [PATCH] Simple batstat ascii art for tmux status bar --- bash/batstat.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 bash/batstat.py diff --git a/bash/batstat.py b/bash/batstat.py new file mode 100755 index 0000000..69f043a --- /dev/null +++ b/bash/batstat.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +#encoding: utf-8 + +import os + +BASE = '/proc/acpi/battery/BAT0' + +STATE = os.path.join(BASE, 'state') +INFO = os.path.join(BASE, 'info') + + +def build_hash(file): + h = {} + if not os.path.exists(file): + return {} + for line in open(file): + key, value = line.split(':') + h[key.replace(' ', '').strip()] = value.strip().strip('\n') + return h + + +state_hash = build_hash(STATE) +info_hash = build_hash(INFO) +#print state_hash, info_hash + +total_capacity = int(info_hash['designcapacity'].split()[0]) +current_capacity = int(state_hash['remainingcapacity'].split()[0]) + +total = int(float(current_capacity) / float(total_capacity) * 10) +bars = total * "|" +print "-{0}{1}+".format(bars, (10 - total) * ' ') + + +