#!/usr/bin/python3 """Simple script for i3blocks for disk free space. Author: flyingscorpio """ import os def get_disk_free_space(disk: str) -> str: """Return available disk space in GiB.""" stat = os.statvfs(disk) total = stat.f_blocks * stat.f_bsize / 1024 / 1024 / 1024 available = stat.f_bavail * stat.f_bsize / 1024 / 1024 / 1024 percentage = (total - available) / total avail_format = "{0:0.1f} GiB free".format(available) percent_format = "({:.1%} used)".format(percentage) return "{} {}".format(avail_format, percent_format) OUTPUT = os.environ['LABEL'] + get_disk_free_space(os.environ["DISK"]) print(OUTPUT)