Last active
February 22, 2026 13:04
-
-
Save ygit/10823c1cb53e698351ffaf06d025ad7d to your computer and use it in GitHub Desktop.
welcome shell script file to be ran on mac first wake
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| #alias welcome='sh -x welcome.sh' | |
| # --- Colors --- | |
| GREEN='\033[0;32m' | |
| YELLOW='\033[1;33m' | |
| CYAN='\033[0;36m' | |
| NC='\033[0m' # No Color | |
| # --- Dry-run support --- | |
| DRY_RUN=false | |
| if [ "$1" = "--dry-run" ] || [ "$1" = "-n" ]; then | |
| DRY_RUN=true | |
| echo "${YELLOW}=== DRY RUN MODE — nothing will be deleted ===${NC}" | |
| fi | |
| # Helper: only execute destructive commands if not in dry-run mode | |
| run() { | |
| if [ "$DRY_RUN" = true ]; then | |
| echo "${YELLOW}[dry-run] $*${NC}" | |
| else | |
| "$@" | |
| fi | |
| } | |
| # --- Timing & Disk Space --- | |
| START_TIME=$(date +%s) | |
| echo "${GREEN}=== Starting System Cleanup ===${NC}" | |
| echo "${CYAN}Disk space before cleanup:${NC}" | |
| df -h / | tail -1 | |
| # ============================================================ | |
| # Package Manager Updates | |
| # ============================================================ | |
| # Ruby gems cleanup | |
| echo "\n${GREEN}--- Ruby Gems ---${NC}" | |
| echo "Updating and cleaning Ruby gems..." | |
| gem update --verbose | |
| gem cleanup | |
| # Homebrew cleanup | |
| echo "\n${GREEN}--- Homebrew ---${NC}" | |
| echo "Updating and cleaning Homebrew..." | |
| brew update --verbose | |
| brew upgrade --verbose | |
| echo "Homebrew cache size before cleanup:" | |
| du -hs ~/Library/Caches/Homebrew/ 2>/dev/null || echo "No Homebrew cache found" | |
| brew cleanup -s | |
| brew autoremove | |
| brew doctor 2>/dev/null || echo "brew doctor found issues (review above)" | |
| # Update Claude Code CLI | |
| echo "\n${GREEN}--- Claude Code CLI ---${NC}" | |
| echo "Updating Claude Code CLI..." | |
| claude update 2>/dev/null || echo "Claude CLI update failed" | |
| claude --version 2>/dev/null || echo "Claude CLI not installed" | |
| # npm/yarn cache cleanup | |
| echo "\n${GREEN}--- npm / yarn ---${NC}" | |
| echo "Cleaning npm cache..." | |
| npm cache verify | |
| run npm cache clean --force 2>/dev/null || echo "npm cache clean failed" | |
| echo "Cleaning yarn cache..." | |
| run yarn cache clean 2>/dev/null || echo "yarn not installed or cache clean failed" | |
| # pip cache cleanup | |
| echo "\n${GREEN}--- pip ---${NC}" | |
| echo "Cleaning pip cache..." | |
| run pip cache purge 2>/dev/null || echo "pip cache clean skipped" | |
| run pip3 cache purge 2>/dev/null || echo "pip3 cache clean skipped" | |
| # ============================================================ | |
| # Xcode Cleanup | |
| # ============================================================ | |
| echo "\n${GREEN}--- Xcode ---${NC}" | |
| # DerivedData | |
| echo "Cleaning Xcode DerivedData..." | |
| du -hs ~/Library/Developer/Xcode/DerivedData/ 2>/dev/null || echo "No DerivedData found" | |
| run rm -rf ~/Library/Developer/Xcode/DerivedData/* | |
| # Archives older than 30 days | |
| echo "Cleaning Xcode Archives (older than 30 days)..." | |
| du -hs ~/Library/Developer/Xcode/Archives/ 2>/dev/null || echo "No Archives found" | |
| run find ~/Library/Developer/Xcode/Archives -mindepth 1 -maxdepth 1 -mtime +30 -exec rm -rf {} + 2>/dev/null | |
| # Xcode module cache & app cache | |
| echo "Cleaning Xcode module cache..." | |
| run rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache" 2>/dev/null | |
| run rm -rf ~/Library/Caches/com.apple.dt.Xcode/* 2>/dev/null | |
| # iOS DeviceSupport cleanup (old iOS versions) | |
| echo "Cleaning iOS DeviceSupport (older than 60 days)..." | |
| du -hs ~/Library/Developer/Xcode/iOS\ DeviceSupport/ 2>/dev/null || echo "No iOS DeviceSupport found" | |
| run find ~/Library/Developer/Xcode/iOS\ DeviceSupport -mindepth 1 -maxdepth 1 -mtime +60 -exec rm -rf {} + 2>/dev/null | |
| # iOS Simulator cleanup | |
| echo "Cleaning iOS Simulators..." | |
| run xcrun simctl delete unavailable 2>/dev/null | |
| du -hs ~/Library/Developer/CoreSimulator/Caches/ 2>/dev/null || echo "No Simulator caches found" | |
| run rm -rf ~/Library/Developer/CoreSimulator/Caches/* 2>/dev/null | |
| # Swift Package Manager cache | |
| echo "Cleaning SPM cache..." | |
| du -hs ~/Library/Caches/org.swift.swiftpm/ 2>/dev/null || echo "No SPM cache found" | |
| run rm -rf ~/Library/Caches/org.swift.swiftpm/ 2>/dev/null | |
| # CocoaPods cache cleanup | |
| echo "\n${GREEN}--- CocoaPods ---${NC}" | |
| echo "Cleaning CocoaPods cache..." | |
| du -hs ~/Library/Caches/CocoaPods/ 2>/dev/null || echo "No CocoaPods cache found" | |
| run pod cache clean --all 2>/dev/null || echo "CocoaPods not installed" | |
| # Carthage cache cleanup | |
| echo "Cleaning Carthage cache..." | |
| du -hs ~/Library/Caches/org.carthage.CarthageKit/ 2>/dev/null || echo "No Carthage cache found" | |
| run rm -rf ~/Library/Caches/org.carthage.CarthageKit/ 2>/dev/null | |
| # ============================================================ | |
| # Mobile / Cross-platform Cleanup | |
| # ============================================================ | |
| # Flutter cleanup | |
| echo "\n${GREEN}--- Flutter ---${NC}" | |
| echo "Cleaning Flutter build caches..." | |
| du -hs ~/Programming/100ms-flutter/example/build/ 2>/dev/null || echo "No Flutter build found" | |
| run rm -rf ~/Programming/100ms-flutter/example/build/ | |
| run flutter clean 2>/dev/null || echo "Flutter clean failed" | |
| # React Native / Android cleanup | |
| echo "\n${GREEN}--- React Native / Android ---${NC}" | |
| echo "Cleaning React Native Android build..." | |
| du -hs ~/Programming/react-native-hms/example/android/build 2>/dev/null || echo "No Android build found" | |
| run rm -rf ~/Programming/react-native-hms/example/android/build | |
| run rm -rf ~/Programming/react-native-hms/example/android/.gradle 2>/dev/null | |
| run rm -rf ~/Programming/react-native-hms/example/ios/build 2>/dev/null | |
| run rm -rf ~/Programming/react-native-hms/example/ios/Pods 2>/dev/null | |
| # Global gradle cache cleanup | |
| echo "\n${GREEN}--- Gradle ---${NC}" | |
| echo "Cleaning Gradle cache (older than 30 days)..." | |
| du -hs ~/.gradle/caches/ 2>/dev/null || echo "No Gradle cache found" | |
| run find ~/.gradle/caches -mindepth 1 -mtime +30 -exec rm -rf {} + 2>/dev/null | |
| # ============================================================ | |
| # Docker Cleanup | |
| # ============================================================ | |
| echo "\n${GREEN}--- Docker ---${NC}" | |
| echo "Cleaning Docker..." | |
| run docker system prune -f 2>/dev/null || echo "Docker not running" | |
| # ============================================================ | |
| # System Cleanup | |
| # ============================================================ | |
| echo "\n${GREEN}--- System ---${NC}" | |
| # DNS cache flush | |
| echo "Flushing DNS cache..." | |
| run sudo dscacheutil -flushcache 2>/dev/null | |
| run sudo killall -HUP mDNSResponder 2>/dev/null | |
| # System & diagnostic logs | |
| echo "Cleaning system logs..." | |
| run sudo rm -rf /private/var/log/asl/*.asl 2>/dev/null | |
| run sudo rm -rf /Library/Logs/DiagnosticReports/* 2>/dev/null | |
| run rm -rf ~/Library/Logs/DiagnosticReports/* 2>/dev/null | |
| # Browser cache (Chrome) | |
| echo "Cleaning Chrome cache..." | |
| du -hs ~/Library/Caches/Google/Chrome/ 2>/dev/null || echo "No Chrome cache found" | |
| run rm -rf ~/Library/Caches/Google/Chrome/ 2>/dev/null | |
| # macOS system caches (be careful with these) | |
| # echo "Cleaning macOS caches..." | |
| # Clean user cache files older than 7 days | |
| # find ~/Library/Caches -type f -mtime +7 -exec rm {} \; 2>/dev/null | |
| # Clean Downloads folder items older than 30 days | |
| # echo "Old Downloads (30+ days):" | |
| # find ~/Downloads -mtime +30 -type f 2>/dev/null | head -20 | |
| # Uncomment to auto-delete old downloads | |
| # find ~/Downloads -mtime +30 -type f -exec rm {} \; 2>/dev/null | |
| # Clean Trash (optional) | |
| echo "Trash size:" | |
| du -hs ~/.Trash/ 2>/dev/null || echo "Trash is empty" | |
| # Uncomment to empty trash | |
| # rm -rf ~/.Trash/* 2>/dev/null | |
| # Purge inactive memory | |
| echo "Purging inactive memory..." | |
| run sudo purge 2>/dev/null | |
| # ============================================================ | |
| # Summary | |
| # ============================================================ | |
| END_TIME=$(date +%s) | |
| ELAPSED=$((END_TIME - START_TIME)) | |
| echo "\n${GREEN}=== Cleanup Complete ===${NC}" | |
| echo "${CYAN}Disk space after cleanup:${NC}" | |
| df -h / | tail -1 | |
| echo "${CYAN}Total time: ${ELAPSED} seconds${NC}" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment