summaryrefslogtreecommitdiff
path: root/users/ryan/linux/waybar/modules
diff options
context:
space:
mode:
authorRyan Schanzenbacher <ryan@rschanz.org>2026-08-24 01:09:49 -0400
committerRyan Schanzenbacher <ryan@rschanz.org>2026-08-24 01:09:49 -0400
commitcabf188ae487120d4b9ac1fe21fff45403a787b4 (patch)
treed9fa0f83426f6465029fb1de334665127e65d1d2 /users/ryan/linux/waybar/modules
parent0ce4331f742863ec03c711c27b0a0dee7e8cc187 (diff)
various fixes to guix
Diffstat (limited to 'users/ryan/linux/waybar/modules')
-rwxr-xr-xusers/ryan/linux/waybar/modules/storage.sh77
1 files changed, 61 insertions, 16 deletions
diff --git a/users/ryan/linux/waybar/modules/storage.sh b/users/ryan/linux/waybar/modules/storage.sh
index 90cc3dc..7cb7249 100755
--- a/users/ryan/linux/waybar/modules/storage.sh
+++ b/users/ryan/linux/waybar/modules/storage.sh
@@ -1,25 +1,70 @@
1#!/bin/sh 1#!/bin/sh
2 2
3mount="/" 3set -eu
4
5mountpoint="/"
4warning=20 6warning=20
5critical=10 7critical=10
6 8
7df -h -P -l "$mount" | awk -v warning=$warning -v critical=$critical ' 9error() {
8/\/.*/ { 10 jq -cn --arg message "$1" '{
9 text=$4 11 text: "N/A",
10 tooltip="Filesystem: "$1"\rSize: "$2"\rUsed: "$3"\rAvail: "$4"\rUse%: "$5"\rMounted on: "$6 12 percentage: 0,
11 use=$5 13 tooltip: $message,
12 exit 0 14 class: "critical"
15 }'
16 exit 0
13} 17}
14END { 18
15 class="" 19line=$(df -hP -l "$mountpoint" 2>/dev/null | tail -n 1) ||
16 gsub(/%$/,"",use) 20 error "Unable to read filesystem statistics"
17 if ((100 - use) < critical) { 21
22# df -P guarantees a single line per filesystem.
23set -- $line
24
25[ "$#" -ge 6 ] || error "Unable to parse filesystem statistics"
26
27filesystem=$1
28size=$2
29used=$3
30available=$4
31use=${5%\%}
32mounted=$6
33
34case "$use" in
35 ''|*[!0-9]*) error "Invalid filesystem usage percentage: $use%" ;;
36esac
37
38free=$((100 - use))
39
40if [ "$free" -le "$critical" ]; then
18 class="critical" 41 class="critical"
19 } else if ((100 - use) < warning) { 42elif [ "$free" -le "$warning" ]; then
20 class="warning" 43 class="warning"
21 } 44else
22 print "{\"text\":\""text"\", \"percentage\":"use",\"tooltip\":\""tooltip"\", \"class\":\""class"\"}" 45 class=""
23} 46fi
24' 47
48jq -cn \
49 --arg text "${use}%" \
50 --argjson percentage "$use" \
51 --arg filesystem "$filesystem" \
52 --arg size "$size" \
53 --arg used "$used" \
54 --arg available "$available" \
55 --arg mounted "$mounted" \
56 --arg class "$class" \
57 '{
58 text: $text,
59 percentage: $percentage,
60 tooltip: (
61 "Filesystem: " + $filesystem +
62 "\rSize: " + $size +
63 "\rUsed: " + $used +
64 "\rAvail: " + $available +
65 "\rUse%: " + $text +
66 "\rMounted on: " + $mounted
67 ),
68 class: $class
69 }'
25 70