Skip to content

Instantly share code, notes, and snippets.

@mattmc3
Last active May 14, 2022 17:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattmc3/e64c58073d6cd64692561d0843ea8ad3 to your computer and use it in GitHub Desktop.
Save mattmc3/e64c58073d6cd64692561d0843ea8ad3 to your computer and use it in GitHub Desktop.
Brew - better Brewfile creation (without the file)
brew_export() {
# brew bundle is a pain... it dumps to a forced Brewfile, and is not
# consistently sorted, making version controling your Brewfile in a dotfile
# repo tricky. #FixedIt
# makes a Brewfile
brew bundle dump --force
# add custom sort column
awkcmd='
BEGIN{FS=OFS=" "}
/^tap/ {print 1 "\t" $0; next}
/^brew/ {print 2 "\t" $0; next}
/^cask/ {print 3 "\t" $0; next}
/^mas/ {print 4 "\t" $0; next}
{print 9 "\t" $0}
'
# output the sorted brewfile, adding then removing the sort column
cat Brewfile | awk "$awkcmd" | sort | awk 'BEGIN{FS="\t";OFS=""}{$1=""; print $0}'
# we never needed this anyway
command rm Brewfile
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment