aboutsummaryrefslogtreecommitdiff
path: root/users/ryan/modules/sketchybar/bar-config/plugins/storage.sh
diff options
context:
space:
mode:
Diffstat (limited to 'users/ryan/modules/sketchybar/bar-config/plugins/storage.sh')
-rwxr-xr-xusers/ryan/modules/sketchybar/bar-config/plugins/storage.sh27
1 files changed, 27 insertions, 0 deletions
diff --git a/users/ryan/modules/sketchybar/bar-config/plugins/storage.sh b/users/ryan/modules/sketchybar/bar-config/plugins/storage.sh
new file mode 100755
index 0000000..b844bb5
--- /dev/null
+++ b/users/ryan/modules/sketchybar/bar-config/plugins/storage.sh
@@ -0,0 +1,27 @@
1#!/usr/bin/env bash
2source "$CONFIG_DIR/colors.sh"
3source "$CONFIG_DIR/icons.sh"
4
5CACHE="/tmp/sketchybar_${NAME}.txt"
6case "$SENDER" in
7 mouse.entered)
8 [ -f "$CACHE" ] && sketchybar --set "$NAME.details" label="$(cat "$CACHE")"
9 sketchybar --set "$NAME" popup.drawing=on; exit 0 ;;
10 mouse.exited)
11 sketchybar --set "$NAME" popup.drawing=off; exit 0 ;;
12esac
13
14# On APFS the real user usage lives on the Data volume; fall back to /
15VOL="/System/Volumes/Data"; [ -d "$VOL" ] || VOL="/"
16
17DF="$(df -h "$VOL" | awk 'NR==2{gsub("%","",$5); print $2, $3, $4, $5}')"
18set -- $DF; SIZE="$1"; USED="$2"; AVAIL="$3"; PCT="$4"
19[ -z "$PCT" ] && exit 0
20
21COLOR=$TEXT
22if [ "$PCT" -ge 90 ]; then COLOR=$RED # custom-storage.critical
23elif [ "$PCT" -ge 80 ]; then COLOR=$YELLOW # custom-storage.warning
24fi
25
26sketchybar --set "$NAME" label="${PCT}% ${DISK}" label.color=$COLOR
27printf '%s' "Disk · ${USED} used of ${SIZE} (${PCT}%) · ${AVAIL} free" > "$CACHE"