Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save papricasix/22614401c7a05f8a7b4e4aaeaa167765 to your computer and use it in GitHub Desktop.
Save papricasix/22614401c7a05f8a7b4e4aaeaa167765 to your computer and use it in GitHub Desktop.
#!/bin/zsh
declare -A visited_formulas
check_formulas() {
for formula in "$@"; do
if [[ -z `brew uses --installed $formula` ]] && ! (( ${+visited_formulas[$formula]} )) && [[ $formula != "brew-cask" ]]; then
read "input?$formula is not depended on by other formulas. Remove? [Y/n] "
visited_formulas[$formula]=1
if [[ "$input" == "Y" ]]; then
brew remove $formula
check_formulas `brew deps --1 --installed $formula`
fi
fi
done
}
echo "Searching for formulas not depended on by other formulas..."
check_formulas `brew list`
@cgrothaus
Copy link

This is great! I use it for ~2 years now. Recently I tweaked it a little bit: upgraded to latest brew CLI behaviour (brew list wants a --formula argument) and added a KEEP_FORMULAS feature. Have a look at https://gist.github.com/cgrothaus/ef9004404e0d168c3d150c409c9d5526 if you like that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment