Skip to content

Instantly share code, notes, and snippets.

@cgrothaus
Forked from papricasix/brew-cleanup-orphans.zsh
Last active October 29, 2020 08:45
Show Gist options
  • Save cgrothaus/ef9004404e0d168c3d150c409c9d5526 to your computer and use it in GitHub Desktop.
Save cgrothaus/ef9004404e0d168c3d150c409c9d5526 to your computer and use it in GitHub Desktop.
#!/bin/zsh
KEEP_FORMULAS=(asdf bat fd fzf git htop httpie hub iftop jq ncdu neovim p7zip ruby-build the_silver_searcher tig tmux watch yq z zsh)
declare -A visited_formulas
for formula ($KEEP_FORMULAS); do
echo "Keeping $formula"
visited_formulas[$formula]=1
done
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 --formula`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment