Intellij IDEA with Ruby plugin で bundle exec foreman start を Run 機能を使って実現する


環境

  • Intellij IDEA 2017.2.6
  • rbenv

手順

Run -> Edit configurations に行き、 + をクリックして Ruby を選択

Configuration を下記画像のように設定

user_nameは適宜変更してください。project_folderはrailsアプリのルートフォルダにします。Nameは表示名なのでなんでも大丈夫です。

Ruby script を設定するところで、Finderが出てくるので Command shift . で隠しファイル・フォルダを表示して選択するか、 Command shift g で直接PATHを入力して設定する。

注意:ここで、Ruby scriptをwhich foremanで出てくる/Users/user_name/.rbenv/shims/foremanにするとIntellij IDEAがシェルスクリプトを実行するところでこけるので、元の実行ファイルを指定します。

Bundlerにチェックを入れる

以上です。

参考

RUBY-12023 how to run foreman within rubymine debug mode
rbenvの切り替えの仕組み…と、他言語での実験 - すぎゃーんメモ

今後調査

bundleコマンドは/Users/user_name/.rbenv/shims/bundleで実行できてるのに、なぜforemanはこけるのか。
出てくるエラー

-e:1:in `load': /Users/user_name/.rbenv/shims/foreman:3: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '(' (SyntaxError)
[ -n "$RBENV_DEBUG" ] && set -x
      ^
/Users/user_name/.rbenv/shims/foreman:3: syntax error, unexpected ']', expecting end-of-input
[ -n "$RBENV_DEBUG" ] && set -x
                     ^
    from -e:1:in `<main>'