Last active
September 25, 2018 12:06
-
-
Save jabbrwcky/4cfd640bee5662f014174c0120d2b0a1 to your computer and use it in GitHub Desktop.
Script to create an inventory of installed brews, casks and taps for Homebrew as Markdown file. Requires an installation of jq (https://stedolan.github.io/jq/)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
if [ $# -eq 1 ]; then | |
file=$1 | |
else | |
file=brew_inventory.md | |
fi | |
cat << EOF >$file | |
# Brew Inventory | |
Inventory created at: $(date) | |
## Brews | |
EOF | |
brew info --json=v1 $(brew list -1) | jq -r '.[] | select(.installed[0].installed_as_dependency == false) | "- [ ] " + .name + ": " + .desc?' >> $file | |
cat << EOF >>$file | |
## Casks | |
EOF | |
for c in $(brew cask list -1); do | |
echo -n "- [ ] $c: " >> $file | |
info=$(brew cask info --json=v1 $c 2>/dev/null) | |
# Some casks fail to produce the JSON output. See https://github.com/Homebrew/homebrew-cask/issues/52427 | |
if [ $? -ne 0 ]; then | |
echo "(failed to read homepage information)" >>$file | |
else | |
echo $info | jq -r '.[].homepage' 2>/dev/null >>$file | |
fi | |
done | |
cat << EOF >>$file | |
## Installed taps | |
EOF | |
for t in $(brew tap 2>/dev/null); do | |
echo "- $t" >> $file | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment