Skip to content

Instantly share code, notes, and snippets.

@sorah
Created October 17, 2014 05:20
Show Gist options
  • Save sorah/48b372dbe5b304afa3ac to your computer and use it in GitHub Desktop.
Save sorah/48b372dbe5b304afa3ac to your computer and use it in GitHub Desktop.
Homebrew relink if necessary
#!/bin/bash
for keg in /usr/local/Library/LinkedKegs/*; do
kegname="$(basename $keg)"
dir="$(find $keg/ -maxdepth 1 -type d | grep '\/\(sbin\|bin\|etc\|var\|lib\|include\|libexec\|share\)$' | head -n1)"
[ -z "${dir}" ] && continue
testee="$(find $dir -type f | head -n1 | sed -e "s|${keg}||")"
[ -f /usr/local/$testee ] || (echo $keg && brew unlink $kegname; brew link --force $kegname)
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment