Skip to content

Instantly share code, notes, and snippets.

@cskeeters
Created June 5, 2014 20:51
Show Gist options
  • Save cskeeters/10ff1295bca93808213d to your computer and use it in GitHub Desktop.
Save cskeeters/10ff1295bca93808213d to your computer and use it in GitHub Desktop.
#!/bin/bash
if [ "$#" -ne "1" ]; then
echo "Usage: $0 package_list"
exit 1
fi
cat $1 | xargs -I {} bash -c "echo {}; brew deps {}" | sort | uniq > /tmp/brew_keep
comm -23 <(brew list -1 | sort) <(cat /tmp/brew_keep) > /tmp/brew_rm
lines=$(cat /tmp/brew_rm | wc -l | sed -e 's/ //g')
if [ "$lines" -ne "0" ]; then
echo "Remove the following packages?"
cat /tmp/brew_rm
read -p "Remove? [yn]" ans
if [ "$ans" == "y" ]; then
brew rm $(cat /tmp/brew_rm)
fi
else
echo "All clean"
fi
rm -f /tmp/brew_keep /tmp/brew_rm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment