From 8eb17bf11d925f76b93aef51ad3f5f6588ae0493 Mon Sep 17 00:00:00 2001 From: "flyingscorpio@arch-desktop" Date: Fri, 24 Apr 2020 12:24:22 +0200 Subject: [PATCH] Add disk usage --- dotfiles/i3/blocks | 10 ++++++++++ dotfiles/i3/scripts/free_disk_space | 22 ++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100755 dotfiles/i3/scripts/free_disk_space diff --git a/dotfiles/i3/blocks b/dotfiles/i3/blocks index cbd77c8..749cd0b 100644 --- a/dotfiles/i3/blocks +++ b/dotfiles/i3/blocks @@ -48,6 +48,16 @@ interval=10 interval=10 LABEL= +[free_disk_space] +interval=10 +LABEL= +DISK=/home/flyingscorpio + +[free_disk_space] +interval=10 +LABEL= +DISK=/run/media/flyingscorpio/Backup + [ccurrency] LABEL=test command=scripts/ccurrency -f USD diff --git a/dotfiles/i3/scripts/free_disk_space b/dotfiles/i3/scripts/free_disk_space new file mode 100755 index 0000000..2776e7c --- /dev/null +++ b/dotfiles/i3/scripts/free_disk_space @@ -0,0 +1,22 @@ +#!/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) + result = stat.f_bavail * stat.f_bsize / 1024 / 1024 / 1024 + + return "{0:0.1f}".format(result) + " GiB free" + + +OUTPUT = os.environ['LABEL'] + get_disk_free_space(os.environ["DISK"]) + +print(OUTPUT)