Skip to content

Commit 89e0b91

Browse files
authored
Revert "Optimize lazy loading performance (#76)"
This reverts commit a0f0a2c.
1 parent a0f0a2c commit 89e0b91

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

zsh-nvm.plugin.zsh

+20-9
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@ _zsh_nvm_install() {
2222
$(builtin cd "$NVM_DIR" && git checkout --quiet "$(_zsh_nvm_latest_release_tag)")
2323
}
2424

25+
_zsh_nvm_global_binaries() {
26+
27+
# Look for global binaries
28+
local global_binary_paths="$(echo "$NVM_DIR"/v0*/bin/*(N) "$NVM_DIR"/versions/*/*/bin/*(N))"
29+
30+
# If we have some, format them
31+
if [[ -n "$global_binary_paths" ]]; then
32+
echo "$NVM_DIR"/v0*/bin/*(N) "$NVM_DIR"/versions/*/*/bin/*(N) |
33+
xargs -n 1 basename |
34+
sort |
35+
uniq
36+
fi
37+
}
38+
2539
_zsh_nvm_load() {
2640

2741
# Source nvm (check if `nvm use` should be ran after load)
@@ -71,7 +85,7 @@ _zsh_nvm_lazy_load() {
7185
if [[ "$NVM_NO_USE" == true ]]; then
7286
global_binaries=()
7387
else
74-
global_binaries=("$NVM_DIR"/v0*/bin/*(N:t) "$NVM_DIR"/versions/*/*/bin/*(N:t))
88+
global_binaries=($(_zsh_nvm_global_binaries))
7589
fi
7690

7791
# Add yarn lazy loader if it's been installed by something other than npm
@@ -81,22 +95,19 @@ _zsh_nvm_lazy_load() {
8195
global_binaries+=('nvm')
8296
global_binaries+=($NVM_LAZY_LOAD_EXTRA_COMMANDS)
8397

84-
# Deduplicate
85-
typeset -U global_binaries
86-
8798
# Remove any binaries that conflict with current aliases
8899
local cmds
89-
IFS=$'\n' cmds=($(whence -w -- "${global_binaries[@]}" 2> /dev/null))
90-
unset IFS
91-
cmds=(${cmds#*": alias"})
92-
cmds=(${(@q-)cmds%": "*})
100+
cmds=()
101+
for bin in $global_binaries; do
102+
[[ "$(which $bin 2> /dev/null)" = "$bin: aliased to "* ]] || cmds+=($bin)
103+
done
93104

94105
# Create function for each command
95106
for cmd in $cmds; do
96107

97108
# When called, unset all lazy loaders, load nvm then run current command
98109
eval "$cmd(){
99-
unset -f ${cmds[@]} > /dev/null 2>&1
110+
unset -f $cmds > /dev/null 2>&1
100111
_zsh_nvm_load
101112
$cmd \"\$@\"
102113
}"

0 commit comments

Comments
 (0)