Skip to content

Commit

Permalink
Simple batstat ascii art for tmux status bar
Browse files Browse the repository at this point in the history
  • Loading branch information
daltonmatos committed Nov 23, 2011
1 parent 013bdfa commit e7846f5
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions 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) * ' ')



0 comments on commit e7846f5

Please sign in to comment.