mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-24 16:53:47 +01:00
feat(nvm): add _omz_nvm_load
function
This commit is contained in:
parent
99e2c31484
commit
1514145a09
@ -42,6 +42,8 @@ as you want:
|
||||
zstyle ':omz:plugins:nvm' lazy-cmd eslint prettier typescript ...
|
||||
```
|
||||
|
||||
There will be a function `_omz_nvm_load` available to load `nvm` without executing any other trigger command.
|
||||
|
||||
#### `.nvmrc` autoload
|
||||
|
||||
Note: _if used at the same time as `lazy`, `autoload` will start working only after nvm has been lazy-loaded_
|
||||
|
@ -20,7 +20,7 @@ if [[ -z "$NVM_DIR" ]] || [[ ! -f "$NVM_DIR/nvm.sh" ]]; then
|
||||
return
|
||||
fi
|
||||
|
||||
function _omz_load_nvm_completion {
|
||||
function _omz_nvm_setup_completion {
|
||||
local _nvm_completion
|
||||
# Load nvm bash completion
|
||||
for _nvm_completion in "$NVM_DIR/bash_completion" "$NVM_HOMEBREW/etc/bash_completion.d/nvm"; do
|
||||
@ -33,12 +33,12 @@ function _omz_load_nvm_completion {
|
||||
break
|
||||
fi
|
||||
done
|
||||
unfunction _omz_load_nvm_completion
|
||||
unfunction _omz_nvm_setup_completion
|
||||
}
|
||||
|
||||
function _omz_setup_autoload {
|
||||
function _omz_nvm_setup_autoload {
|
||||
if ! zstyle -t ':omz:plugins:nvm' autoload; then
|
||||
unfunction _omz_setup_autoload
|
||||
unfunction _omz_nvm_setup_autoload
|
||||
return
|
||||
fi
|
||||
|
||||
@ -68,13 +68,13 @@ function _omz_setup_autoload {
|
||||
add-zsh-hook chpwd load-nvmrc
|
||||
|
||||
load-nvmrc
|
||||
unfunction _omz_setup_autoload
|
||||
unfunction _omz_nvm_setup_autoload
|
||||
}
|
||||
|
||||
if zstyle -t ':omz:plugins:nvm' lazy; then
|
||||
# Call nvm when first using nvm, node, npm, pnpm, yarn, corepack or other commands in lazy-cmd
|
||||
zstyle -a ':omz:plugins:nvm' lazy-cmd nvm_lazy_cmd
|
||||
nvm_lazy_cmd=(nvm node npm npx pnpm pnpx yarn corepack $nvm_lazy_cmd) # default values
|
||||
nvm_lazy_cmd=(_omz_nvm_load nvm node npm npx pnpm pnpx yarn corepack $nvm_lazy_cmd) # default values
|
||||
eval "
|
||||
function $nvm_lazy_cmd {
|
||||
for func in $nvm_lazy_cmd; do
|
||||
@ -84,14 +84,16 @@ if zstyle -t ':omz:plugins:nvm' lazy; then
|
||||
done
|
||||
# Load nvm if it exists in \$NVM_DIR
|
||||
[[ -f \"\$NVM_DIR/nvm.sh\" ]] && source \"\$NVM_DIR/nvm.sh\"
|
||||
_omz_load_nvm_completion
|
||||
_omz_setup_autoload
|
||||
\"\$0\" \"\$@\"
|
||||
_omz_nvm_setup_completion
|
||||
_omz_nvm_setup_autoload
|
||||
if [[ \"\$0\" != _omz_nvm_load ]]; then
|
||||
\"\$0\" \"\$@\"
|
||||
fi
|
||||
}
|
||||
"
|
||||
unset nvm_lazy_cmd
|
||||
else
|
||||
source "$NVM_DIR/nvm.sh"
|
||||
_omz_load_nvm_completion
|
||||
_omz_setup_autoload
|
||||
_omz_nvm_setup_completion
|
||||
_omz_nvm_setup_autoload
|
||||
fi
|
||||
|
Loading…
Reference in New Issue
Block a user