@ledsun blog

無味の味は佳境に入らざればすなわち知れず

RubyMineのターミナルが壊れた話

RubyMineのターミナルのシェルがおかしいです。

パスから/usr/local/binが消えてしまった。rbenvが動かせません

rbenvが動かせません。

シェルにはfish-shellを使っています。 fish-shellの起動時に、次のエラーメッセージが出ます。

~/.config/fish/config.fish (line 1): 
rbenv init -|psub
^
in command substitution
        called on line 39 of file ~/.config/fish/config.fish
from sourcing file ~/.config/fish/config.fish
        called on line 185 of file /usr/local/Cellar/fish/3.1.0/share/fish/config.fish
in function '.' with arguments '/Users/shigerunakajima/.config/fish/config.fish'
        called on line 20 of file /Applications/RubyMine.app/Contents/plugins/terminal/fish/config.fish
from sourcing file /Applications/RubyMine.app/Contents/plugins/terminal/fish/config.fish
        called during startup
~/.config/fish/config.fish: Unknown error while evaluating command substitution
from sourcing file ~/.config/fish/config.fish
        called on line 185 of file /usr/local/Cellar/fish/3.1.0/share/fish/config.fish
in function '.' with arguments '/Users/shigerunakajima/.config/fish/config.fish'
        called on line 20 of file /Applications/RubyMine.app/Contents/plugins/terminal/fish/config.fish
from sourcing file /Applications/RubyMine.app/Contents/plugins/terminal/fish/config.fish
        called during startup
Welcome to fish, the friendly interactive shell

~/.config/fish/config.fish の39行目の status --is-interactive; and source (rbenv init -|psub) でエラーが出ています。

これはなんのためのコードでしょうか? rbenv init - は、つぎのようなrbenvのPATHなどを初期化するシェルスクリプトを出力します。

set -gx PATH '/Users/shigerunakajima/.rbenv/shims' $PATH
set -gx RBENV_SHELL fish
source '/usr/local/Cellar/rbenv/1.1.2/libexec/../completions/rbenv.fish'
command rbenv rehash 2>/dev/null
function rbenv
  set command $argv[1]
  set -e argv[1]

  switch "$command"
  case rehash shell
    source (rbenv "sh-$command" $argv|psub)
  case '*'
    command rbenv "$command" $argv
  end
end

psubというのはコマンドの実行結果を名前付きパイプ(仮想ファイルみたいなもの?)に書き込むfishのコマンドです。

たとえば、次のようにうごきます。

~ echo (rbenv init -|psub)
/var/folders/3m/82sq4tnn62d59h7h6wzn6w340000gn/T//.psub.s8MwzlfDwx

この出力された名前付きパイプをsourceすると、rbenvが初期化されます。

結局 /usr/local/bin/rbenv にパスが通ってないからエラーになるようです。

PATHに/usr/local/binを追加してみましょう。

fishらしく set -U fish_user_paths /usr/local/bin $fish_user_paths でユニバーサルなPATHに追加してみても、変わりません。

~/.config/fish/config.fish の39行目の直前で set -g fish_user_paths "/usr/local/bin /usr/local/opt/ruby/bin" $fish_user_paths してPATHに追加してみます。変わりません。

~/.config/fish/config.fish の39行目の直前で set PATH /usr/local/bin $PATH すると、うごきました!

config.fishなのにfish-shellのコマンドが効かない、エラーが出ないのに効果が出ないのは、不思議な感じがします。

蛇足 RubyMineのPATHどこからくるのか?(不明)

path_helperについて。Mac OSX 版 - それマグで! によると、 mac のパス設定は path_helper というのがあり、path_helper は /etc/paths のをPATHに反映するらしい。

/etc/pathsを確認してみます。

~ cat /etc/paths
/usr/local/bin
/usr/bin
/bin
/usr/local/sbin
/usr/sbin
/sbin

/usr/local/bin が入っている。RubyMineがpath_helperを使わないのかもしれません。

RubyMineの設定をみてみます。

f:id:ledsun:20200304043810p:plain
RubyMineの設定

システムの環境変数を使うって有るし、/usr/local/bin も入っています・・・