1
0
Fork 0
pull/8/head
Samuel Clements 13 years ago
parent f3e9ea7c86
commit 579a1498df

@ -7,23 +7,27 @@ import sys
""" Config """ """ Config """
output_length = 10 output_length = 10
hide_when_charge_is_above = 95 hide_when_charge_is_above = 90
blank_when_battery_full = True blank_when_battery_full = True
filled_char, empty_char = u'', u'' filled_char, empty_char = u'', u''
""" Read battery charge """ """ Read battery charge """
def read_battery_percent (sp, regex): def read_battery_percent (sp, regex):
""" Reads the battery charge as an integer between 0 and 100, using a given process and regex. """
import subprocess, re import subprocess, re
process = subprocess.Popen(sp, stdout=subprocess.PIPE) process = subprocess.Popen(sp, stdout=subprocess.PIPE)
output = process.communicate()[0].strip() output = process.communicate()[0].strip()
return int(re.search(regex,output).group(1)) return int(re.search(regex, output, re.MULTILINE).group(1))
if sys.platform.startswith('darwin'): if sys.platform.startswith('darwin'):
""" Reads the battery charge as an integer between 0 and 100, using 'pmset -g batt' """ """ OSX - 'pmset -g batt' """
charge = read_battery_percent(["pmset", "-g", "batt"], "^.+([\d]+)\%") charge = read_battery_percent(["pmset", "-g", "batt"], "^.+\t([\d]+)\%")
elif sys.platform.startswith('freebsd'):
""" Freebsd - 'acpiconf -i 0' """
charge = read_battery_percent(["acpiconf", "-i", "0"], "")
else: else:
""" Reads the battery charge as an integer between 0 and 100, using 'acpi -b' """ """ Linux - 'acpi -b' """
charge = read_battery_percent(["acpi", "-b"], "^Battery 0: .+, ([\d]+)\%") charge = read_battery_percent(["acpi", "-b"], "^Battery 0: .+, ([\d]+)\%")
""" Output """ """ Output """

@ -1,11 +1,22 @@
# #
# A light theme showing only the needed information. # A light theme showing only minimal information in colour:
# - Current directory, optionally prefixed with the user and host
# - Git repo and branch, with markers for staged and unstaged changes.
# - Battery change meter on the right, with colour based on charge,
# and only appearing when battery is below 90% charge.
# #
# Authors: # Authors:
# Samuel Clements <samuel@borntyping.co.uk> # Samuel Clements <samuel@borntyping.co.uk>
# #
# Screenshot: # Screenshots:
# http://i.imgur.com/JSFRj.png # http://misc.borntyping.co.uk/twain-screenshots/Twain.png
#
# http://misc.borntyping.co.uk/twain-screenshots/Repo.png
# http://misc.borntyping.co.uk/twain-screenshots/Repo%20%28with%20markers%29.png
#
# http://misc.borntyping.co.uk/twain-screenshots/Charge25.png
# http://misc.borntyping.co.uk/twain-screenshots/Charge50.png
# http://misc.borntyping.co.uk/twain-screenshots/Charge75.png
# #
function battery_charge { function battery_charge {

Loading…
Cancel
Save