@@ -22,6 +22,20 @@ _zsh_nvm_install() {
22
22
$( builtin cd " $NVM_DIR " && git checkout --quiet " $( _zsh_nvm_latest_release_tag) " )
23
23
}
24
24
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
+
25
39
_zsh_nvm_load () {
26
40
27
41
# Source nvm (check if `nvm use` should be ran after load)
@@ -71,7 +85,7 @@ _zsh_nvm_lazy_load() {
71
85
if [[ " $NVM_NO_USE " == true ]]; then
72
86
global_binaries=()
73
87
else
74
- global_binaries=(" $NVM_DIR " /v0 * /bin/ * (N:t) " $NVM_DIR " /versions/ * / * /bin/ * (N:t ))
88
+ global_binaries=($( _zsh_nvm_global_binaries ) )
75
89
fi
76
90
77
91
# Add yarn lazy loader if it's been installed by something other than npm
@@ -81,22 +95,19 @@ _zsh_nvm_lazy_load() {
81
95
global_binaries+=(' nvm' )
82
96
global_binaries+=($NVM_LAZY_LOAD_EXTRA_COMMANDS )
83
97
84
- # Deduplicate
85
- typeset -U global_binaries
86
-
87
98
# Remove any binaries that conflict with current aliases
88
99
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
93
104
94
105
# Create function for each command
95
106
for cmd in $cmds ; do
96
107
97
108
# When called, unset all lazy loaders, load nvm then run current command
98
109
eval " $cmd (){
99
- unset -f ${ cmds[@]} > /dev/null 2>&1
110
+ unset -f $cmds > /dev/null 2>&1
100
111
_zsh_nvm_load
101
112
$cmd \"\$ @\"
102
113
}"
0 commit comments