Skip to content

Instantly share code, notes, and snippets.

@thriveth
Last active June 13, 2017 22:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thriveth/f408687b2f90f2f8ac36abaa2d4c4bfc to your computer and use it in GitHub Desktop.
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 …
#!/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