Created
May 26, 2016 23:28
-
-
Save meyerbaptiste/56584512223165a4e1e1f88815b46ed0 to your computer and use it in GitHub Desktop.
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 | |
# 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