Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't get chruby to play nice with vim :(. #196

Closed
myronmarston opened this issue Sep 4, 2013 · 20 comments
Closed

Can't get chruby to play nice with vim :(. #196

myronmarston opened this issue Sep 4, 2013 · 20 comments

Comments

@myronmarston
Copy link

I just got a new MacBook Pro (first time in ~ 3 years) and decided to give chruby a go this time round instead of RVM.

I've sourced chruby in my ~/.zshrc:

source /usr/local/opt/chruby/share/chruby/chruby.sh
source /usr/local/share/chruby/auto.sh

In my vim config, I have:

set shell=$SHELL\ -l

.ruby-version in my project root is:

1.9.3-p448

...yet, when I run :!ruby --version it shows me that it's running Apple's default system ruby:

ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]

Any ideas what I'm doing wrong?

@alindeman
Copy link

The output of :!echo $PATH might be useful. I wonder where chruby's paths are?

Another thing to try (on OS X) is sudo mv /etc/{zshenv,zshrc} which fixes a weird OS X bug that tends to mangle $PATH when you spawn new login shells (lifted from thoughtbot/laptop)

@pda
Copy link

pda commented Sep 4, 2013

Are you running zsh via homebrew?

Note this part of the Caveats for brew info zsh:

If you have administrator privileges, you must fix an Apple miss
configuration in Mac OS X 10.7 Lion by renaming /etc/zshenv to
/etc/zprofile, or Zsh will have the wrong PATH when executed
non-interactively by scripts.

I'm pretty sure when I had the same problem as you, doing sudo mv /etc/zshenv /etc/zprofile and restarting vim/tmux/zsh/iTerm2 fixed it.

@myronmarston
Copy link
Author

The output of :!echo $PATH might be useful. I wonder where chruby's paths are?

/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin:/Users/myron/.gem/ruby/1.9.3/bin:/Users/myron/.rubies/ruby-1.9.3-p448/lib/ruby/gems/1.9.1/bin:/Users/myron/.rubies/ruby-1.9.3-p448/bin:/Users/myron/code/clusterpluck/support/ec2-api-tools-1.3-57419/bin

Trying the other suggestions now...

@mislav
Copy link

mislav commented Sep 4, 2013

You probably run zsh. You can set the shell to be set shell=bash in Vim if you don't absolutely require zsh in Vim.

The zsh problem is likely due to Mac OS X shipping with /etc/zshenv which should be /etc/zprofile. Fix that with:

sudo mv /etc/zshenv /etc/zprofile

This fixes more issues down the road than just Vim.

@mislav
Copy link

mislav commented Sep 4, 2013

Whoops, the guys above already said the same thing. Sorry for the noise!

@postmodern
Copy link
Owner

@myronmarston chruby is definitely modifying PATH, but it appears that your shell configuration is blindly prepending /usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/local/git/bin before the ruby's bin/. Double check your shell configuration, also I have seen issues before where OSX's path_helper messes with PATH when spawning sub-shells.

@pda
Copy link

pda commented Sep 4, 2013

For some background into the problem:

/etc/zshenv calls eval $(/usr/libexec/path_helper -s) which rebuilds (and re-orders) the path.

From the path_helper man page:

The path_helper utility reads the contents of the files in the directories
/etc/paths.d and /etc/manpaths.d and appends their contents to the PATH and
MANPATH environment variables respectively.

Prior to reading these directories, default PATH and MANPATH values are
obtained from the files /etc/paths and /etc/manpaths respectively.
/etc/manpaths respectively.

And from the Zsh man pages:

Commands are first read from /etc/zshenv; this cannot be overridden.
…
As /etc/zshenv is run for all instances of zsh, it is important that it be kept as small as possible.
…
If the shell is a login shell, commands are read from /etc/zprofile and then
$ZDOTDIR/.zprofile.  Then, if the shell is interactive, commands are read from
/etc/zshrc and then $ZDOTDIR/.zshrc.  Finally, if the shell is a login shell,
/etc/zlogin and $ZDOTDIR/.zlogin are read.

… So Mac OS's path mangling should really only be done for login shells, otherwise the PATH environment doesn't survive sub-shells. That means /etc/zprofile should be ideal. But if for some reason you only want it on interactive login shells, /etc/zshrc would also work. But never /etc/zshenv.

@postmodern
Copy link
Owner

See also: UNIX Shell Initialization.

@pda
Copy link

pda commented Sep 4, 2013

See also: UNIX Shell Initialization.

Nice.

@myronmarston
Copy link
Author

Thanks for all the help, everyone...it's nice to get some prompt help :).

This is definitely an area where my understanding is lacking; I need to get better. I tried the mvs suggested above and it's not helping, unfortunately. However, if I remove the set shell=$SHELL\ -l from my vim config (as recommended by the wiki), it works fine. Go figure.

Still don't quite understand it, but at least I've got it working now.

@postmodern
Copy link
Owner

@pda suggestion for improving the wiki for Vim integration? I use set shell=$SHELL\ -l with bash and /etc/profile.d/chruby.sh.

@alindeman
Copy link

prompt help

pun?

@myronmarston
Copy link
Author

pun?

Not intentional, actually :).

@pda
Copy link

pda commented Sep 4, 2013

@pda suggestion for improving the wiki for Vim integration?

I've done a few fresh Mac OS setups lately. Personally I just do this:

  • Install chruby and ruby-install via homebrew.
  • Install latest ruby stable version via ruby-build.
  • Create a ~/.ruby-version file.
  • My portable Zsh config loads chruby: https://github.com/pda/dotzsh/blob/master/ruby.zsh#L12-L17
  • sudo mv /etc/{zshenv,zprofile} (I lost hours tracking that down the first time).

My .vimrc has never had/needed any special shell support.
(I run vim ← zsh ← tmux ← zsh ← iTerm2, which may differ from other setups e.g. MacVim).

@mislav
Copy link

mislav commented Sep 5, 2013

@myronmarston The mv alone didn't have effect since you had $SHELL -l in your vimrc. The -l flag means you opted in to boot the shell in login mode, which means that the new /etc/zprofile (after having done mv) would get sourced.

Generally, you probably never want -l when starting a shell until you have a strong reason why you want the shell to start in login mode.

@myronmarston
Copy link
Author

Generally, you probably never want -l when starting a shell until you have a strong reason why you want the shell to start in login mode.

Good to know. I was just following the Vim instructions in the wiki. Sounds like that should be changed...

@tubbo
Copy link

tubbo commented Oct 3, 2013

@postmodern i've been wrestling with $SHELL\ -l, and it doesn't really make much sense when you think about it (login shells are only supposed to be invoked once, when you "log in"). using set shell=$SHELL works fine for me, after renaming /etc/zshenv to /etc/zprofile.

@postmodern
Copy link
Owner

@tubbo I forced the -l option so the login configuration would be loaded (I have chruby configured in /etc/profile.d/chruby.sh). I suppose vim was default to using dash or bash, when you wanted zsh?

@tubbo
Copy link

tubbo commented Oct 3, 2013

yeah, it defaults to bash or sh right?

@postmodern
Copy link
Owner

On Fedora's vim 7.4, shell defaults to /bin/bash.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants