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

rbenv init creates duplicates in PATH #1573

Open
RichardFevrier opened this issue May 16, 2024 · 3 comments
Open

rbenv init creates duplicates in PATH #1573

RichardFevrier opened this issue May 16, 2024 · 3 comments

Comments

@RichardFevrier
Copy link

Hello, adding rbenv init - | source in config.fish adds twice the shims path (same issue on nodenv but not on pyenv).

@mislav
Copy link
Member

mislav commented May 16, 2024

Hi, if you run rbenv init - fish, you can inspect the script that will be eval'd by your shell. This is it for me:

set -gx PATH '/Users/mislav/.rbenv/shims' $PATH
set -gx RBENV_SHELL fish
command rbenv rehash 2>/dev/null
function rbenv
  set command $argv[1]
  set -e argv[1]

  switch "$command"
  case rehash shell
    rbenv "sh-$command" $argv|source
  case '*'
    command rbenv "$command" $argv
  end
end

I only see the shims path being added once. Could it be that something else is adding another shims path, or that you're running a shell within a shell and that both edited PATH?

@jasonkarns
Copy link
Member

jasonkarns commented May 16, 2024

It sounds like rbenv init is being invoked twice.

rbenv-init should not create duplicates but rather proceeds to prepend the sims to PATH regardless if they're already present. If your shell setup is already calling rbenv-init elsewhere, then the second invocation would create a second entry in PATH.

When rbenv-init runs, its job is to place the shims at the beginning of PATH. If it's called twice, they'll be added twice. The recommended fix is to not call rbenv-init twice.

Some more background: rbenv initially tried to be "clever" and only add the shims if they weren't present: 03fa148

This causes no end of problems thanks to poor handling of *rc and *profile files by some OS configurations (most notably, OS X back in the day). #369
See also the general problem: https://stackoverflow.com/questions/13058578/how-to-prevent-tmux-from-filling-up-the-global-path-variable-with-duplicated-pat

So the de-duping was subsequently reverted: e2173df

Current behavior is now intentional (rbenv-init simply prepends to PATH regardless of existing value).

@RichardFevrier
Copy link
Author

RichardFevrier commented May 16, 2024

Thanks for the answers, yes I've read the doc and saw rbenv init - fish before posting and also upgraded to the latest commit rbenv and checked my fish config 10 times, so yes I'm sure there are no duplicates.

Invoked only once and if I remove it and logout to be sure, no shims anymore (from rbenv) in my path.
I've also checked other globals and universal vars from fish.

Btw Fish already handles dupes in PATH if you use the fish idiomatic way fish_add_path -g $HOME/.rbenv/shims

I'll try on a second machine and let you know.

Edit:
Forgot to mention if you want to see my config by yourself here it is.

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

3 participants