Skip to content

Instantly share code, notes, and snippets.

@gera2ld
Created October 28, 2020 05:36
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 gera2ld/b4c974721616f3e9d5d10410acf71825 to your computer and use it in GitHub Desktop.
Save gera2ld/b4c974721616f3e9d5d10410acf71825 to your computer and use it in GitHub Desktop.
Clean unused packages installed by Homebrew
expected=(
# paste packages to keep here
aria2
deno
fzf
yarn
)
brew_clean() {
while
leaves=(`brew leaves`)
to_be_removed=()
for dep in $leaves; do
if [ ${expected[(ie)$dep]} -gt ${#expected} ]; then
to_be_removed+=( $dep )
fi
done
[ ${#to_be_removed} -gt 0 ]
do
echo To be removed: ${to_be_removed[@]}
read -q confirm\?"Confirm? [y/n] "
echo
if [ "$confirm" = y ]; then
brew uninstall ${to_be_removed[@]}
else
break
fi
done
if [ ${#to_be_removed} -eq 0 ]; then
echo All clean
fi
}
brew_clean
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment