Open HaleTom opened 4 years ago
I was having the same issue, and I thought I would share my workaround in case someone might find it useful.
Basically, I declare a directory where, if I open a shell in it or it's sub-dirs, nvm is loaded.
# <-------- .zshrc -------->
# <------- export zsh-nvm variables **above** ----->
# Declare the directory(s) where you code
export NVM_LAZY_AUTO_DIR=("$HOME/code")
activate_nvm() {
# checking dir in path, and if node is a shell function (not loaded)
if [[ $PWD =~ $NVM_LAZY_AUTO_DIR && "$(type node)" = *'a shell function'* ]]; then
print 'Activating nvm...'
# trigger loading
node --version
# cd into same dir to activate auto_use
cd $PWD
fi
}
# use this function if LAZY_LOAD is true
if [[ ( $NVM_LAZY_LOAD ) ]]; then
precmd_functions+=(activate_nvm)
fi
# <-------- source zsh-nvm **below** --------->
_zsh_nvm_auto_use
will return early ifnvm_find_nvmrc
is not found, which will be the case when lazy loading.Would you consider including a copy of
nvm_find_nvmrc
inside your code if lazy loading, so that auto use can work as intended, beforenvm
,node
, etc are run for the first time?