Skip to content

Instantly share code, notes, and snippets.

@adrenalinehit
Created March 30, 2026 21:40
Show Gist options
  • Select an option

  • Save adrenalinehit/bfc0a2b4ba770fe8c330135640d88133 to your computer and use it in GitHub Desktop.

Select an option

Save adrenalinehit/bfc0a2b4ba770fe8c330135640d88133 to your computer and use it in GitHub Desktop.
#!/bin/bash
# --- CONFIGURATION ---
# Define paths to clean. Format: "Label|Path"
TARGETS=(
"User Caches|~/Library/Caches"
"System Logs|~/Library/Logs"
"Xcode DerivedData|~/Library/Developer/Xcode/DerivedData"
"Xcode Archives|~/Library/Developer/Xcode/Archives"
"Xcode iOS DeviceSupport|~/Library/Developer/Xcode/iOS DeviceSupport"
"Xcode Documentation|~/Library/Developer/Xcode/DocumentationCache"
"Android Gradle Caches|~/.gradle/caches"
"Android Studio Caches|~/Library/Caches/Google/AndroidStudio*"
"CocoaPods Cache|~/Library/Caches/CocoaPods"
"NPM Cache|~/.npm/_logs"
"Yarn Cache|~/Library/Caches/Yarn"
"Homebrew Cache|~/Library/Caches/Homebrew"
"VS Code Cached Data|~/Library/Application Support/Code/CachedData"
"VS Code Workspace Storage|~/Library/Application Support/Code/User/workspaceStorage"
"Spotify Cache|~/Library/Caches/com.spotify.client"
"User Trash|~/.Trash"
)
DRY_RUN=true
TOTAL_SAVED=0
# Parse arguments
if [[ "$1" == "--nuke" ]]; then
DRY_RUN=false
echo "⚠️ WARNING: LIVE RUN ACTIVATED. Files will be deleted."
else
echo "🔍 DRY RUN: Enumerating potential savings (Run with --nuke to delete)."
fi
echo "---------------------------------------------------"
printf "%-30s | %-10s\n" "Location" "Size"
echo "---------------------------------------------------"
# Helper to expand tilde
expand_path() {
echo "${1/#\~/$HOME}"
}
for item in "${TARGETS[@]}"; do
LABEL="${item%%|*}"
RAW_PATH="${item##*|}"
PATH_EXPANDED=$(expand_path "$RAW_PATH")
if [ -d "$PATH_EXPANDED" ] || [ -e "$PATH_EXPANDED" ]; then
# Calculate size in KB for summing, then format for display
SIZE_KB=$(du -sk "$PATH_EXPANDED" 2>/dev/null | cut -f1)
SIZE_HUMAN=$(du -sh "$PATH_EXPANDED" 2>/dev/null | cut -f1)
printf "%-30s | %-10s\n" "$LABEL" "$SIZE_HUMAN"
TOTAL_SAVED=$((TOTAL_SAVED + SIZE_KB))
if [ "$DRY_RUN" = false ]; then
# Delete contents but keep the root folder for some system paths
rm -rf "${PATH_EXPANDED:?}"/* 2>/dev/null
fi
fi
done
# --- SPECIAL COMMANDS ---
if [ "$DRY_RUN" = false ]; then
echo "---------------------------------------------------"
echo "📦 Running Tool Cleanups..."
command -v brew >/dev/null && brew cleanup -s >/dev/null 2>&1
command -v xcrun >/dev/null && xcrun simctl delete unavailable >/dev/null 2>&1
# Only prune docker if the daemon is running
if docker info >/dev/null 2>&1; then
docker system prune -f >/dev/null 2>&1
fi
fi
echo "---------------------------------------------------"
# Convert KB to GB for final report
TOTAL_GB=$(echo "scale=2; $TOTAL_SAVED / 1024 / 1024" | bc)
echo "ESTIMATED TOTAL SAVINGS: ${TOTAL_GB} GB"
echo "---------------------------------------------------"
if [ "$DRY_RUN" = true ]; then
echo "To actually free up this space, run: ./clean_mac.sh --nuke"
else
echo "✅ Cleanup Complete."
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment