Skip to content

Instantly share code, notes, and snippets.

@Mastersam07
Last active September 9, 2024 12:33
Show Gist options
  • Save Mastersam07/1568d12666fc4581c0f425c723c3472a to your computer and use it in GitHub Desktop.
Save Mastersam07/1568d12666fc4581c0f425c723c3472a to your computer and use it in GitHub Desktop.
A script to clean all flutter projects on your machine
#!/bin/bash
# Directories to exclude
EXCLUDE_DIRS=(
"/System"
"/Library"
"/Applications"
"/Volumes"
"/opt/homebrew"
"/opt/homebrew/bin/fvm"
"/Users/codefarmer/fvm"
"/Users/codefarmer/development"
"/Users/codefarmer/.pub-cache"
"$HOME/.vscode/extensions"
"$HOME/.vscode-insiders/extensions"
"/Users/codefarmer/.cursor/extensions"
"/Users/codefarmer/.shorebird"
"/Users/codefarmer/.mason-cache"
)
# Convert EXCLUDE_DIRS array into a find exclude format
EXCLUDE_PARAMS=""
for dir in "${EXCLUDE_DIRS[@]}"; do
EXCLUDE_PARAMS="$EXCLUDE_PARAMS -path $dir -prune -o"
done
# Find all Flutter projects by looking for pubspec.yaml files, excluding specified directories
echo "Searching for Flutter projects across your Mac, excluding: ${EXCLUDE_DIRS[*]}..."
eval "find / $EXCLUDE_PARAMS -name 'pubspec.yaml' -print 2>/dev/null" | while read -r pubspec; do
# Get the directory of the Flutter project
project_dir=$(dirname "$pubspec")
# Move to the project directory
cd "$project_dir"
# Clean the Flutter project
echo "Cleaning Flutter project in $project_dir..."
flutter clean
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment