LoginSignup
8
8

More than 5 years have passed since last update.

`bundle exec`って毎回打つのめんどくさい人のための設定

Posted at

Railsで何度も何度もbundle execって打つのがめんどくさいので、現在のディレクトリにGemfileがあったら頭にbundle execをつけて実行するスクリプトを使うと便利です。

具体例(Windowsでnyaosを使ってる場合)

rake{
    if exist "Gemfile" then
        bundle exec rake %*
    else
        cmd /c rake %*
    endif
}

cap{
    if exist "Gemfile" then
        bundle exec cap %*
    else
        cmd /c cap %*
    endif
}


guard{
    if exist "Gemfile" then
        bundle exec guard %*
    else
        cmd /c guard %*
    endif
}


rspec{
    if exist "Gemfile" then
        bundle exec rspec %*
    else
        cmd /c rspec %*
    endif
}

一括で定義する方法がわからなかったので愚直に何度も書きました。

Unix系のOSでbashを使ってる場合

for func in guard rspec rake cap; do
        eval "
        ${func}() {
                local foo=(command ${func})
                [ -e 'Gemfile' ] && foo=(bundle exec ${func})
                \"\${foo[@]}\" \"\$@\"
        }
        "
done

参考

いつものように教えてもらったものばかりです。

bash スクリプトから nyaos のスクリプトへの変換 - QA@IT

How to define similar bash function at once - Unix & Linux Stack Exchange

8
8
0

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
8
8