Created
January 20, 2017 15:16
-
-
Save ellisvalentiner/ce46bfb562f1c360bd3624b3d3b212dc 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