chruby
chruby copied to clipboard
.ruby-version not read with `cd foo && cmd` in zsh
While investigating #241, and possibly related to #160, I discovered this issue with zsh:
# zsh
cd /tmp
mkdir foo
echo '1.9.3' > foo/.ruby-version
ruby -v # ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
# incorrect:
cd foo && ruby -v # ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
ruby -v # ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux]
cd ..
# correct:
cd foo
ruby -v # ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux]
Also happens with cd foo; cmd.
Contrast this to bash, where cd foo && ruby -v prints the same version as if they'd been entered completely separately:
# bash
cd foo && ruby -v && cd .. # ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux]
cd foo
ruby -v # ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux]
It looks like using chpwd instead of preexec would fix this problem, but I don't know zsh enough to recognise any pitfalls with that approach.
Actually that looks like it also fixes #241 and auto-switching would work for zsh subshells:
$ ruby -v
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
$ chruby
ruby-1.9.3-p448
ruby-2.0.0-p247
ruby-2.0.0-p353
$ (
subsh> cd foo
subsh> ruby -v
subsh> )
ruby 1.9.3p448 (2013-06-27 revision 41675) [x86_64-linux]
$ ruby -v
ruby 2.0.0p353 (2013-11-22 revision 43784) [x86_64-linux]
I can fix both issues in one PR by moving to chpwd if that's acceptable.
Any updates on this issue? Any workaround?
Are there any downsides to using both preexec_functions and chpwd_functions?
@postmodern I'm not sure. That same issue came up at https://github.com/postmodern/chruby/pull/246#commitcomment-5218445 in my (now very-outdated) PR for this fix.