Created
August 24, 2018 11:00
-
-
Save thriveth/26959a0f8fe2b5cd54aed0a6a442de26 to your computer and use it in GitHub Desktop.
Python script to return a zsh-formatted string to show battery status in your prompt.
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 python3 | |
# -*- coding=utf-8 -*- | |
""" This script requires acpi to be installed """ | |
import math | |
import subprocess | |
import sys | |
# Output | |
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] == b'Charging': | |
filled_symbol = u'▸' | |
empty_symbol = '▹' | |
elif batt_info[0].split()[-1] == b'Discharging': | |
filled_symbol = u'◂' | |
empty_symbol = '◃' | |
else: | |
filled_symbol = u'●' # '●▪' | |
empty_symbol = '-' # u'\u25cb' | |
filled = int(math.ceil(percnt / 10.)) * filled_symbol # u'●' | |
empty = int(total_slots - len(filled)) * empty_symbol # u'\u25cb' | |
out = (filled + empty).encode('utf-8') | |
outstring = ( | |
b"%F{blue}"+out+b"%F{$reset_color%}" if batt_info[0].split()[-1] == b'Charging' | |
else b"%F{green}"+out+b"%F{$reset_color%}" if len(filled) > 5 | |
else b"%F{yellow}"+out+b"%F{$reset_color%}" if len(filled) > 2 | |
else b"%F{red}"+out+b"%F{$reset_color%}" | |
) | |
sys.stdout.write(outstring.decode()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment