Skip to content

Instantly share code, notes, and snippets.

@bennylope
Created November 22, 2017 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bennylope/c7969c33eea835930f977cbaf40adb03 to your computer and use it in GitHub Desktop.
Save bennylope/c7969c33eea835930f977cbaf40adb03 to your computer and use it in GitHub Desktop.
A short script for performing brew cleanup for all but specified packages. The 'cleanup' command can either be used for specific packages or for all - there is no exclusion option - and this means cleanup on older packages that I want.
#!/usr/bin/env bash
# Clean all but specified packages of old homebrewed installed packages
declare -a exclude=(python python3 python34 python35 python36 python27 pypy ruby node)
for PACKAGE in $(brew ls)
do
SENTINEL=false
for EXCLUDE in "${exclude[@]}"
do
if [ "$PACKAGE" = "$EXCLUDE" ]; then
SENTINEL=true
fi
done
if [ "$SENTINEL" = false ] ; then
echo "Cleaning up $PACKAGE"
brew cleanup $PACKAGE
else
echo "Skipping cleanup on $PACKAGE"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment