Skip to content

Instantly share code, notes, and snippets.

@thibaultcha
Last active November 19, 2023 18:34
Show Gist options
  • Save thibaultcha/10712262 to your computer and use it in GitHub Desktop.
Save thibaultcha/10712262 to your computer and use it in GitHub Desktop.
Ever wondered which of your homebrew formulas are unused legacy dependencies? Run this!
#!/bin/bash
GREEN="\033[1;32m";
RESET="\033[m";
echo "Searching for standalone formulae...";
dependencies=();
for formula in $(brew list); do
deps=(`brew uses $formula --installed | tr '\n' ' '`);
# Add the formula if it's being used by another, installed one
if [ ${#deps[@]} -lt 1 ]; then
dependencies+=($formula);
fi
done
if [ ${#dependencies[@]} -gt 1 ]; then
echo -e "${GREEN}${#dependencies[@]} standalone formulae found${RESET}";
for formula in "${dependencies[@]}"; do
echo $formula;
done
echo "None of these formulae are used by any other formula, some of them might be legacy dependencies...";
else
echo "No standalone formula found";
fi
@jacobwgillespie
Copy link

Hey, just FYI there's a built-in command for this, which happens to be pretty quick since it analyzes the whole dependency tree at once:

$ brew leaves

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