cfg/.config/i3blocks/disk
Knut Ahlers 4ae353dc51
Bring more color to the i3bar
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2018-12-03 15:22:12 +01:00

52 lines
1.1 KiB
Python
Executable File

#!/usr/bin/env python
import subprocess
import sys
CRIT = 90.0
MOUNT_BLACKLIST = ['/dev', '/efi', '/proc', '/run', '/sys', '/tmp']
def main():
output = subprocess.check_output([
'sh', '-c', 'df -a -B 1 | awk \'{ printf "%s\\t%d\\t%d\\n", $6, $2, $4 }\''
]).decode('utf-8')
fs = {}
for line in output.split('\n'):
if len(line) == 0 or line[0] != '/':
continue
(mountpoint, total, available) = line.split('\t')
fs[mountpoint] = (total, available)
color = '#50fa7b'
strings = []
for mount, data in fs.items():
skip = False
for b in MOUNT_BLACKLIST:
if mount.startswith(b):
skip = True
if skip:
continue
usage = 0.0
if float(data[0]) > 0.0:
usage = (1 - float(data[1])/float(data[0])) * 100.0
if usage > CRIT:
color = '#dd0000'
strings.append('<span color="#8FAAFC">{}</span>: <span color="{}">{:.0f}%</span>'.format(
mount,
color,
usage,
))
print('\ufaed '+' '.join(strings))
if __name__ == '__main__':
main()