Battery gauge requires a python script, 'battcharge.py' added to $ZSH/lib/ directory to work properly.
Cleaned up zshmarks again, now uses proper return codes in case bookmark not found, etc.
This commit is contained in:
Jocelyn Mallon 2011-10-08 13:06:09 -07:00
commit 59e2f43237
5 changed files with 78 additions and 16 deletions

38
lib/battcharge.py Executable file
View file

@ -0,0 +1,38 @@
#!/usr/bin/env python
# coding=UTF-8
import math, subprocess
p = subprocess.Popen(["ioreg", "-rc", "AppleSmartBattery"], stdout=subprocess.PIPE)
output = p.communicate()[0]
o_max = [l for l in output.splitlines() if 'MaxCapacity' in l][0]
o_cur = [l for l in output.splitlines() if 'CurrentCapacity' in l][0]
b_max = float(o_max.rpartition('=')[-1].strip())
b_cur = float(o_cur.rpartition('=')[-1].strip())
charge = b_cur / b_max
charge_threshold = int(math.ceil(10 * charge))
# Output
total_slots, slots = 10, []
filled = int(math.ceil(charge_threshold * (total_slots / 10.0))) * u''
empty = (total_slots - len(filled)) * u''
out = (filled + empty).encode('utf-8')
import sys
color_green = '%{%}'
color_yellow = '%{%}'
color_red = '%{%}'
color_reset = '%{%}'
color_out = (
color_green if len(filled) > 6
else color_yellow if len(filled) > 4
else color_red
)
out = color_out + out + color_reset
sys.stdout.write(out)