Created
June 25, 2012 07:30
-
-
Save uasi/2987161 to your computer and use it in GitHub Desktop.
brew install-version (a Homebrew command that install a specific version of a formula with ease)
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 zsh | |
if [[ $# -lt 2 ]]; then | |
print -P "%UUsage%u: brew install-version [install options] FORMULA VERSION" | |
exit 1 | |
fi | |
formula= | |
version= | |
install_opts=() | |
versions_opts=() | |
for arg in $*; do | |
if [[ $arg =~ '^--' ]]; then | |
install_opts+=$arg | |
[[ $arg == --devel ]] && versions_opts+=$arg | |
continue | |
fi | |
if [[ -z $formula ]]; then | |
formula=$arg | |
continue | |
fi | |
version=$arg | |
done | |
versions=`brew versions $versions_opts $formula` | |
if [[ $? -ne 0 ]]; then | |
print -P "%F{red}%UError%u%f: No available formula for $formula" | |
exit 1 | |
fi | |
object=$(echo $versions | awk '$1=="'$version'" {print $4":"$5}') | |
object=${object/:`brew --prefix`\//:} | |
if [[ -z $object ]]; then | |
print -P "%F{red}%UError%u%f: No available formula for $formula version $version" | |
exit 1 | |
fi | |
formula_cache="`brew --cache`/Formula/$formula.rb" | |
git --git-dir="`brew --repository`/.git" show $object > $formula_cache | |
if [[ $? -eq 0 ]]; then | |
brew install $install_opts $formula_cache | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment