Skip to content

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

Closed

Description

@myronmarston

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?

Activity

  1. alindeman commented on Sep 4, 2013

    @alindeman

    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)

  2. pda commented on Sep 4, 2013

    @pda

    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.

  3. myronmarston commented on Sep 4, 2013

    @myronmarston
    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...

  4. mislav commented on Sep 4, 2013

    @mislav

    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.

  5. mislav commented on Sep 4, 2013

    @mislav

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

  6. postmodern commented on Sep 4, 2013

    @postmodern
    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.

  7. pda commented on Sep 4, 2013

    @pda

    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.

  8. postmodern commented on Sep 4, 2013

    @postmodern
    Owner
  9. pda commented on Sep 4, 2013

    @pda

    See also: UNIX Shell Initialization.

    Nice.

  10. myronmarston commented on Sep 4, 2013

    @myronmarston
    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.

  11. postmodern commented on Sep 4, 2013

    @postmodern
    Owner

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

  12. alindeman commented on Sep 4, 2013

    @alindeman

    prompt help

    pun?

  13. myronmarston commented on Sep 4, 2013

    @myronmarston
    Author

    pun?

    Not intentional, actually :).

  14. pda commented on Sep 4, 2013

    @pda

    @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).

  15. mislav commented on Sep 5, 2013

    @mislav

    @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.

  16. myronmarston commented on Sep 5, 2013

    @myronmarston
    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...

  17. tubbo commented on Oct 3, 2013

    @tubbo

    @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.

  18. postmodern commented on Oct 3, 2013

    @postmodern
    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?

  19. tubbo commented on Oct 3, 2013

    @tubbo

    yeah, it defaults to bash or sh right?

  20. postmodern commented on Oct 3, 2013

    @postmodern
    Owner

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

  21. added a commit that references this issue on Jul 11, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions