diff options
Diffstat (limited to 'users/ryan/modules/sketchybar/bar-config/plugins/storage.sh')
| -rwxr-xr-x | users/ryan/modules/sketchybar/bar-config/plugins/storage.sh | 27 |
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 | ||
| 2 | source "$CONFIG_DIR/colors.sh" | ||
| 3 | source "$CONFIG_DIR/icons.sh" | ||
| 4 | |||
| 5 | CACHE="/tmp/sketchybar_${NAME}.txt" | ||
| 6 | case "$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 ;; | ||
| 12 | esac | ||
| 13 | |||
| 14 | # On APFS the real user usage lives on the Data volume; fall back to / | ||
| 15 | VOL="/System/Volumes/Data"; [ -d "$VOL" ] || VOL="/" | ||
| 16 | |||
| 17 | DF="$(df -h "$VOL" | awk 'NR==2{gsub("%","",$5); print $2, $3, $4, $5}')" | ||
| 18 | set -- $DF; SIZE="$1"; USED="$2"; AVAIL="$3"; PCT="$4" | ||
| 19 | [ -z "$PCT" ] && exit 0 | ||
| 20 | |||
| 21 | COLOR=$TEXT | ||
| 22 | if [ "$PCT" -ge 90 ]; then COLOR=$RED # custom-storage.critical | ||
| 23 | elif [ "$PCT" -ge 80 ]; then COLOR=$YELLOW # custom-storage.warning | ||
| 24 | fi | ||
| 25 | |||
| 26 | sketchybar --set "$NAME" label="${PCT}% ${DISK}" label.color=$COLOR | ||
| 27 | printf '%s' "Disk · ${USED} used of ${SIZE} (${PCT}%) · ${AVAIL} free" > "$CACHE" | ||
