Skip to content

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

Closed
@taralbass

Description

@taralbass

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.

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