Last active
October 17, 2017 00:05
-
-
Save EvelynSubarrow/f2adbfa528795eee945753ca91071d91 to your computer and use it in GitHub Desktop.
Lazy i3 statusbar
This file contains 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 | |
import json, time, subprocess | |
from datetime import datetime | |
# Dependencies | |
import psutil | |
import netifaces | |
print('{"version": 1}') | |
print('[') | |
print('[],') | |
def line(colour, text): | |
# Nano likes to syntax highlight '#' (d 35) wherever it appears. This annoys me. A lot. | |
return {"color": chr(35) + colour, "full_text": text} | |
while True: | |
out = [ | |
line("33DDDD", "{:.2f}/{:.2f}".format( | |
psutil.virtual_memory().active/(1024**3), | |
psutil.virtual_memory().total/(1024**3), | |
)), | |
line("4444DD", "CPU: " + ", ".join("{:2.0f}".format(x) for x in psutil.cpu_percent(percpu=True) )), | |
line("4444DD", ", ".join("{:+2.0f}".format(x.current) for x in psutil.sensors_temperatures()["coretemp"] )), | |
] | |
power = psutil.sensors_battery() | |
if power: | |
if int(power.secsleft) <= 0: | |
time_text = "∞"*power.power_plugged or "-" | |
else: | |
m,s = divmod(power.secsleft, 60) | |
h,m = divmod(m, 60) | |
time_text = "{}h {}m {}s".format(h, m, s) | |
out.extend([ | |
line("33DDDD", "{:2.0f}{}".format(power.percent, "+"*power.power_plugged or "-")), | |
line("33DDDD", time_text), | |
]) | |
else: | |
out.extend([ | |
line("33DDDD", "-"), | |
line("33DDDD", "-"), | |
]) | |
ssid = None | |
try: | |
ssid = subprocess.check_output(["iwgetid", "-r"]).rstrip() | |
except subprocess.CalledProcessError as e: | |
pass | |
for i in netifaces.interfaces(): | |
if i=="lo": continue | |
addrs = netifaces.ifaddresses(i) | |
if netifaces.AF_INET not in addrs and not netifaces.AF_INET6 in addrs: continue | |
t = "/".join([a["addr"] for a in addrs.get(netifaces.AF_INET, [])]) | |
fl = "6" * (netifaces.AF_INET6 in addrs) | |
if fl: fl = " +" + fl | |
out.append(line("4444DD", "{}: {}{}".format(i, t, fl))) | |
if ssid: out.append(line("4444DD", ssid.decode("utf8"))) | |
out.append(line("F2FFFF", datetime.now().strftime("%F T %T"))) | |
print(json.dumps(out) + ",") | |
time.sleep(1) |
This file contains 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
bar { | |
status_command ~/bin/i3_status.py | |
separator_symbol "/" | |
strip_workspace_numbers yes | |
font pango:monospace 8 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment