File size: 1,231 Bytes
e4d97fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env zsh
set -euo pipefail

# hide_cache_contents.sh
# Hides all files and folders inside .cache except the Assets folder by setting
# the macOS `hidden` file flag (chflags hidden). Run with `--undo` to remove
# the hidden flag.

SCRIPT_DIR="$(cd "$(dirname "${0}")" && pwd)"
CACHE_DIR="$SCRIPT_DIR/.cache"

if [ ! -d "$CACHE_DIR" ]; then
  echo ".cache directory not found at $CACHE_DIR"
  exit 1
fi

ACTION="hide"
if [ "${1:-}" = "--undo" ]; then
  ACTION="unhide"
fi

echo "Will $ACTION items in: $CACHE_DIR (preserving Assets)"

for entry in "$CACHE_DIR"/.* "$CACHE_DIR"/*; do
  # skip nonexistent globs
  [ -e "$entry" ] || continue
  base=$(basename "$entry")
  # skip current/parent
  if [ "$base" = "." ] || [ "$base" = ".." ]; then
    continue
  fi
  # always preserve Assets (do not hide it)
  if [ "$base" = "Assets" ]; then
    if [ "$ACTION" = "hide" ]; then
      chflags nohidden "$entry" 2>/dev/null || true
    else
      chflags nohidden "$entry" 2>/dev/null || true
    fi
    continue
  fi

  if [ "$ACTION" = "hide" ]; then
    chflags hidden "$entry" 2>/dev/null || true
  else
    chflags nohidden "$entry" 2>/dev/null || true
  fi
done

echo "Done: $ACTION completed. Use '$0 --undo' to revert."