mirror of
https://github.com/apisnetworks/pyenv.git
synced 2026-11-30 19:59:01 +00:00
init: Improve zsh init performance (#3638)
When deduplicating PATH, use zsh's $path and array replacement instead of starting a bash subprocess. Speeds up `eval "$(pyenv init - zsh)"` by about 100ms (~20%). --------- Co-authored-by: umbralOptimatum <umbralOptimatum@users.noreply.github.com>
This commit is contained in:
1 parent
e1065c334c
commit
2e578d9738
2 files changed
+16
No files matched your search
@@ -449,6 +449,10 @@ function print_path() {
|
||||
echo '$Env:PATH="$(($Env:PATH -split '"':'"' | where { -not ($_ -match '"'${PYENV_ROOT}/shims'"') }) -join '"':'"')"'
|
||||
print_path_prepend_shims
|
||||
;;
|
||||
zsh )
|
||||
echo 'path=("${(@)path:#"${PYENV_ROOT}/shims"}")'
|
||||
print_path_prepend_shims
|
||||
;;
|
||||
* )
|
||||
# Some distros (notably Debian-based) set Bash's SSH_SOURCE_BASHRC compilation option
|
||||
# that makes it source `bashrc` under SSH even when not interactive.
|
||||
|
||||
@@ -292,6 +292,18 @@ echo "\$Env:PATH"
|
||||
assert_output "${PYENV_ROOT}/shims:${BATS_TEST_DIRNAME}/nonexistent:${OLDPATH//${PYENV_ROOT}\/shims:/}"
|
||||
}
|
||||
|
||||
@test "removes existing shims from PATH (zsh)" {
|
||||
command -v zsh >/dev/null || skip "-- zsh not installed"
|
||||
OLDPATH="$PATH"
|
||||
export PATH="${BATS_TEST_DIRNAME}/nonexistent:${PYENV_ROOT}/shims:$PATH"
|
||||
run zsh -df - <<!
|
||||
eval "\$(pyenv-init -)"
|
||||
echo "\$PATH"
|
||||
!
|
||||
assert_success
|
||||
assert_output "${PYENV_ROOT}/shims:${BATS_TEST_DIRNAME}/nonexistent:${OLDPATH//${PYENV_ROOT}\/shims:/}"
|
||||
}
|
||||
|
||||
@test "adds shims to PATH with --no-push-path if they're not on PATH" {
|
||||
export PATH="${BATS_TEST_DIRNAME}/../libexec:/usr/bin:/bin:/usr/local/bin"
|
||||
run bash -e <<!
|
||||
|
||||
Reference in new issue
Block a user