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