Skip to content

Instantly share code, notes, and snippets.

@hlorand
Created September 3, 2023 02:58
Show Gist options
  • Save hlorand/ffd84891bf03017107bc2a4bc43aa103 to your computer and use it in GitHub Desktop.
Save hlorand/ffd84891bf03017107bc2a4bc43aa103 to your computer and use it in GitHub Desktop.
List Homebrew package sizes and dependencies
#!/bin/bash
# list installed brew packages and list its dependencies
# https://www.thingy-ma-jig.co.uk/blog/22-09-2014/homebrew-list-packages-and-what-uses-them
brew list -1 | while read cask; do echo -ne "\x1B[1;34m $cask \x1B[0m"; brew uses $cask --installed | awk '{printf(" %s ", $0)}'; echo ""; done
# list installed brew packages sizes
# https://stackoverflow.com/questions/40065188/get-size-of-each-installed-formula-in-homebrew
for pkg in `brew list --formula -1 | grep -vE '\.|\.\.'`
do echo $pkg `brew info $pkg | grep -E '[0-9]* files, ' | sed 's/^.*[0-9]* files, \(.*\)).*$/\1/' | awk '{print $1;}/[0-9]$/{s+=$1};/[mM][bB]$/{s+=$1*(1024*1024);next};/[kK][bB]$/{s+=$1*1024;next} END { suffix=" KMGT"; for(i=1; s>1024 && i < length(suffix); i++) s/=1024; printf "\t(all versions: %0.1f%s)",s,substr(suffix, i, 1), $3; }'`
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment