postmodern / chruby

Changes the current Ruby
MIT License
2.86k stars 190 forks source link

can't easily run chruby from vim or mc #305

Closed x-yuri closed 9 years ago

x-yuri commented 9 years ago

I enabled chruby system-wide and now the easiest way to run it from vim or mc I can think of:

bash -lc 'chruby'

And to run something with some specific version of ruby:

bash -lc 'chruby 2.1 && ruby --version'

Am I doing it wrong? Is there an easier way?

postmodern commented 9 years ago

Run chruby in the terminal, then run your text editor of choice. For temporary shell sessions, use the :sh vim command to drop down to a shell.

postmodern commented 9 years ago

I almost forgot, we already have some tips on Vim integration on the Wiki.

x-yuri commented 9 years ago

So from what I can tell, chruby creates a shell function of the same name, which is not inherited. And I'm supposed to have /usr/local/share/chruby/chruby.sh sourced in the current shell before doing anything. Is this all I've got to do? Does the state get inherited, like current ruby version?

postmodern commented 9 years ago

You must source chruby.sh / auto.sh in your Shell Configuration, that way chruby is loaded into every shell and sub-shell.

x-yuri commented 9 years ago

Okay, I looked into it. /usr/local/share/chruby/chruby.sh defines a shell function of the same name, which is not inherited. So, for it work /usr/local/share/chruby/chruby.sh must be sourced in every shell where this function is needed. Which means system-wide setup doesn't makes much sense. I need to put it into ~/.bashrc anyway, unless I want to use it in only login shells:

$ chruby
   ruby-2.0.0-p247
 * ruby-2.1.5
$ bash
$ chruby
bash: chruby: command not found

As for the state, it's stored in environment variables which are inherited. That is, no need to source /usr/local/share/chruby/chruby.sh unless you're going to switch to different ruby.