Last active
December 16, 2015 10:38
-
-
Save kuoe0/5421086 to your computer and use it in GitHub Desktop.
install specific version formula with homebrew
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
#============================================================================= | |
# FileName: brew_version | |
# Desc: install specific version formula with homebrew | |
# Usage: brew_version <formula> <version> [param1 param2 ...] | |
# Author: KuoE0 | |
# Email: [email protected] | |
# HomePage: http://kuoe0.ch/ | |
#============================================================================= | |
# /usr/bin/env bash | |
formula=$1 | |
version=$2 | |
# concatenate addition parameters | |
for ((i=3; i <= $#; ++i)); do | |
param=$param' '${!i} | |
done | |
# open homebrew directory | |
cd `brew --prefix` | |
# list all version avalible | |
version_list=$(brew versions $formula 2>/dev/null) | |
# regex for remove version number | |
re_version="s/[[:digit:]]+(\.[[:digit:]]+)*[[:space:]]*//" | |
# get the command for specific formula | |
checkout_cmd=$(echo "$version_list" | grep $version | sed -E $re_version) | |
echo $checkout_cmd | |
# git checkout to specific version | |
`$checkout_cmd` | |
# unlink formula | |
echo "brew unlink $formula" | |
brew unlink $formula | |
# install specific formula and use addition parameters | |
echo "brew install $formula $param" | |
brew install $formula | |
# switch to the specific formula | |
echo "brew switch $formula $version" | |
brew switch $formula $version | |
# reset homebrew repo | |
reset_cmd=$(echo "$version_list" | sed -n '1p' | sed -E $re_version) | |
echo "$reset_cmd" | |
`$reset_cmd` | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment