Skip to content

Instantly share code, notes, and snippets.

@ellisvalentiner
Created January 20, 2017 15:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ellisvalentiner/ce46bfb562f1c360bd3624b3d3b212dc to your computer and use it in GitHub Desktop.
Save ellisvalentiner/ce46bfb562f1c360bd3624b3d3b212dc to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Notes:
# - tsort requires as input a stream of pairs (a, b) where package a depends
# on package b. If package a has k > 1 dependencies, we should have k lines
# associated to it; if package a has no dependencies, then we should have a
# single line (a, a). The pairs are just space delimited, no parentheses.
# the little awk program below formats the data that way for tsort.
# - tsort outputs the order from bottom to top; that's why we need to reverse
# it with tail -r.
brew list \
| while read l; do echo -n "$l "; echo $(brew deps $l); done \
| awk 'NF == 1 {print $1, $1} NF > 1 {for (i=1;i<=NF;i++) print $1, $i}' \
| tsort \
| tail -r \
| while read l; do echo -n "$l "; brew reinstall $l; done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment