Skip to content

Instantly share code, notes, and snippets.

@uasi
Created June 25, 2012 07:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save uasi/2987161 to your computer and use it in GitHub Desktop.
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)
#!/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