mirror of
https://github.com/lukechilds/zsh-nvm.git
synced 2025-02-06 09:55:31 +08:00
Refactor lazy loading
This commit is contained in:
parent
2a9ee9e10f
commit
1c6d8dd15e
@ -22,6 +22,13 @@ _zsh_nvm_install() {
|
|||||||
$(cd "$NVM_DIR" && git checkout --quiet "$(_zsh_nvm_latest_release_tag)")
|
$(cd "$NVM_DIR" && git checkout --quiet "$(_zsh_nvm_latest_release_tag)")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_zsh_nvm_global_binaries() {
|
||||||
|
ls "$NVM_DIR"/versions/*/*/bin/* |
|
||||||
|
xargs basename |
|
||||||
|
sort |
|
||||||
|
uniq
|
||||||
|
}
|
||||||
|
|
||||||
_zsh_nvm_load() {
|
_zsh_nvm_load() {
|
||||||
|
|
||||||
# Source nvm
|
# Source nvm
|
||||||
@ -49,17 +56,17 @@ _zsh_nvm_load() {
|
|||||||
_zsh_nvm_lazy_load() {
|
_zsh_nvm_lazy_load() {
|
||||||
|
|
||||||
# Get all global node module binaries (including node)
|
# Get all global node module binaries (including node)
|
||||||
local node_globals=($(ls "$NVM_DIR"/versions/*/*/bin/* | xargs basename | sort | uniq))
|
local global_binaries=($(_zsh_nvm_global_binaries))
|
||||||
|
|
||||||
# Add nvm
|
# Add nvm
|
||||||
node_globals+=('nvm')
|
global_binaries+=('nvm')
|
||||||
|
|
||||||
# Create function for each command
|
# Create function for each command
|
||||||
for cmd in $node_globals; do
|
for cmd in $global_binaries; do
|
||||||
|
|
||||||
# When called, unset all lazy loaders, load nvm then run current command
|
# When called, unset all lazy loaders, load nvm then run current command
|
||||||
eval "$cmd(){
|
eval "$cmd(){
|
||||||
unset -f $node_globals
|
unset -f $global_binaries
|
||||||
_zsh_nvm_load
|
_zsh_nvm_load
|
||||||
$cmd \"\$@\"
|
$cmd \"\$@\"
|
||||||
}"
|
}"
|
||||||
|
Loading…
Reference in New Issue
Block a user