users/ryan/modules/sketchybar/bar-config/plugins/storage.sh
8d7aa6e03293de5432a33e6ed55f3f4b2a4f095c
· 960 B · 27 lines
raw
| 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" |