LoginSignup
37
39

More than 5 years have passed since last update.

Homebrew でバージョンを指定してインストールするコマンド作った

Last updated at Posted at 2012-12-26

homebrewでバージョンを指定してインストールするが便利だったのでコマンドにしてみました。

homebrew-install-version

#!/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

ダウンロードしてパスの通ったディレクトリに置き、ファイル名をbrew-install-versionとして chmod +x してください。

brew install-version FORMULA VERSION で特定のバージョンのソフトウェアをインストールします。有効なバージョンは brew versions FORMULA で確認できます。

インストールしたバージョンが brew upgrade でアップグレードされないよう固定するには brew pin FORMULA とします。

gist はこちら: https://gist.github.com/2987161

37
39
3

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
37
39