Last active
June 13, 2017 22:09
-
-
Save thriveth/f408687b2f90f2f8ac36abaa2d4c4bfc to your computer and use it in GitHub Desktop.
Small Python script that returns a string encoding (linux) laptop battery status. Each char represents 10%. a `-` means empty, `π` means charging, and `π` means running on battery power. Strongly inspired by Steve Losh's zsh prompt http://stevelosh.com/blog/2010/02/my-extravagant-zsh-prompt/#my-right-prompt-battery-capacity, but changed quite a β¦
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# coding=UTF-8 | |
import math, subprocess, sys | |
batt_info = subprocess.check_output('acpi').split(b',') | |
batt_info = [l.strip() for l in batt_info] | |
percnt = int(batt_info[1][:-1]) | |
total_slots, slots = 10, [] | |
if batt_info[0].split()[-1] == 'Charging': | |
filled_symbol = u'π' | |
else: | |
filled_symbol = u'π' | |
empty_symbol = '-' | |
filled = int(math.ceil(percnt / 10.)) * filled_symbol | |
empty = int(total_slots - len(filled)) *empty_symbol | |
out = (empty + filled).encode('utf-8') | |
out = (filled + empty).encode('utf-8') | |
if sys.version_info.major == 3: # Smells like ugly hacks | |
out = out.decode() | |
print(out) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment