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

fish-specific PATH changes get lost when changing ruby versions #31

Closed
taralbass opened this issue Jul 2, 2017 · 6 comments · Fixed by #39
Closed

fish-specific PATH changes get lost when changing ruby versions #31

taralbass opened this issue Jul 2, 2017 · 6 comments · Fixed by #39

Comments

@taralbass
Copy link

My PATH variable is not being properly maintained when chruby-fish changes ruby versions. In particular, anything added to the PATH variable in config.fish gets lost.

In the example below, /home/tbass/chruby_test/bin is an empty dir that I added to my path just to illustrate the problem.

tbass@stardust ~> env | grep "^PATH="
PATH=/home/tbass/chruby_test/bin:/usr/local/sbin:/usr/local/bin:/usr/bin
tbass@stardust ~> chruby 2.4.0
tbass@stardust ~> env | grep "^PATH="
PATH=/home/tbass/.gem/ruby/2.4.0/bin:/home/tbass/.rubies/ruby-2.4.0/lib/ruby/gems/2.4.0/bin:/home/tbass/.rubies/ruby-2.4.0/bin:/usr/local/sbin:/usr/local/bin:/usr/bin
tbass@stardust ~> chruby system
tbass@stardust ~> env | grep "^PATH="
PATH=/usr/local/sbin:/usr/local/bin:/usr/bin
tbass@stardust ~> 

Not that after changing to 2.4.0, /home/tbass/chruby_test/bin is no longer in the PATH, nor is it there after returning to system ruby.

Here is my config.fish:

source /usr/local/share/chruby/chruby.fish
source /usr/local/share/chruby/auto.fish

set -x PATH /home/tbass/chruby_test/bin $PATH

I played around a bit and I believe the problem is that when the bchruby function invokes bash, it invokes a login shell, which resets the PATH according to the bash login process instead of using the PATH that was passed in as part of the environment. So when it extracts the PATH back out, it has done more than just apply chruby's modification to the current PATH. Instead, it has applied chruby's modification to whatever the bash login PATH is, abandoning the original PATH altogether.

When I remove the -l option to the bash call, it seems to work fine for me, but I don't know if there are any other implications for removing it.

@dalizard
Copy link

dalizard commented Apr 17, 2018

I am having similar (the same?) problem. I am unable to prepend to PATH:

~ $ cat ~/.config/fish/config.fish | grep PATH
# Add .bin to PATH
set -x PATH ~/.bin /usr/local/sbin $PATH
~ $ echo $PATH
/Users/foo/.gem/ruby/2.5.0/bin /Users/foo/.rubies/ruby-2.5.0/lib/ruby/gems/2.5.0/bin /Users/foo/.rubies/ruby-2.5.0/bin /usr/local/bin /usr/bin /bin /usr/sbin /sbin /Users/foo/.bin /usr/local/sbin
~ $ fish --version
fish, version 2.7.1
~ $ chruby --version
chruby: 0.3.9
chruby-fish: 0.8.1
~ $ cat ~/.config/fish/config.fish | tail -n 3
# Ruby manager
source /usr/local/share/chruby/chruby.fish
source /usr/local/share/chruby/auto.fish
~ $

If I drop the source /usr/local/share/chruby/auto.fish line from config.fish everything works as expected.

@JeanMertz
Copy link
Owner

I've released a new version with some path-related fixes. If you're still using chruby, I encourage you to try it out. I'll close this issue, but feel free to let me know if the problem isn't fixed. I'm not sure I have the time to investigate this anytime soon, but maybe I can squeeze it in somewhere.

@der-flo
Copy link

der-flo commented May 17, 2019

I can confirm this problem is NOT fixed, at least not for my configuration:

[ -f /usr/local/share/chruby/chruby.fish ]; and source /usr/local/share/chruby/chruby.fish
set -g fish_user_paths /Applications/MacVim.app/Contents/bin $fish_user_paths

As soon as I call chruby, my custom PATH addition is postfixed instead of prefixed:

$echo $PATH
/Applications/MacVim.app/Contents/bin /usr/local/bin /usr/bin /bin /usr/sbin /sbin
$ chruby 2.6.3
$ echo $PATH
/Users/<user>/.gem/ruby/2.6.3/bin /Users/<user>/.rubies/ruby-2.6.3/lib/ruby/gems/2.6.0/bin /Users/<user>/.rubies/ruby-2.6.3/bin /usr/local/bin /usr/bin /bin /usr/sbin /sbin /Applications/MacVim.app/Contents/bin

@JeanMertz
Copy link
Owner

Thanks for letting me know @der-flo. I've re-opened the issue, but don't have the time right now to investigate. I'll circle back to this when I can.

@ioquatix
Copy link
Collaborator

I'm running into this issue too.

@technicalpickles
Copy link

I ran into this as well. In my case, I'm on a M1 and had /opt/homebrew/bin on the PATH, and I was trying to figure out why which git was showing /usr/bin/git. I tracked it down to chruby-fish, and it seems to be this issue.

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

Successfully merging a pull request may close this issue.

6 participants