Reuse the bash init code from pyenv-init

Merged
IG
10d ago
+17-0

Following the discussion here I reused the code that prevents duplicate path segments from pyenv init, only changed it from multiple echos to heredoc.

I can't say that I'm a fan of this code

  • It's way too complex;
  • It invokes Bash on some the other shells, e.g. pyenv init - zsh ->
PATH="$(bash --norc -ec 'IFS=:; paths=($PATH);
...

which is not good. Unit test in pyenv init is more relaxed than here and don't catch it.

.. But if this code was accepted in pyenv init, it should be good as well here ๐Ÿ˜„


Summary by cubic

Reuses the duplicate-path cleanup logic from pyenv init in pyenv-virtualenv-init for bash, so repeated initialization no longer accumulates duplicate shims entries in PATH.

  • Removes any existing shims path from PATH before prepending it.
  • Updates the bash init test to match the new output.