Skip to content

Instantly share code, notes, and snippets.

@dakcarto
Last active January 27, 2021 18:02
Show Gist options
  • Star 8 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save dakcarto/1280b1b352db5e00f80d to your computer and use it in GitHub Desktop.
Save dakcarto/1280b1b352db5e00f80d to your computer and use it in GitHub Desktop.
#!/bin/bash
# assign env var, if set
HB="${HOMEBREW_PREFIX:=/usr/local}"
find -L "${HB}/opt" -name 'INSTALL_RECEIPT.json' -maxdepth 2 -print > /tmp/homebrew-installed.txt
printf '' > /tmp/homebrew-installed-w-options.txt
NAME=''
OPTIONS=''
NAMES=''
NAME_OPTS=''
while IFS= read -r file
do
# get the formula name
NAME=$(printf "$file" | sed -E "s|^${HB}/opt/([^/]+)/INSTALL_RECEIPT.json$|\1|")
# get, cleanup and append used options
OPTIONS=$(grep -l -v "\"used_options\":\[\]" "$file")
if [ -z "$OPTIONS" ]; then
NAMES+="${NAME}
"
else
OPTIONS=$(sed -E -e 's/^.+"used_options":\[([^]]+)\].*$/\1/' -e 's/"//g' -e "s/,/ /g" "$file")
NAME_OPTS+="${NAME} ${OPTIONS}
"
fi
done < /tmp/homebrew-installed.txt
printf "${NAME_OPTS}" >> /tmp/homebrew-installed-w-options.txt
printf "${NAMES}" >> /tmp/homebrew-installed-w-options.txt
open /tmp/homebrew-installed-w-options.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment