Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NVM_AUTO_USE doesn't work with NVM_LAZY_LOAD until too late #72

Open
HaleTom opened this issue Oct 30, 2020 · 1 comment
Open

NVM_AUTO_USE doesn't work with NVM_LAZY_LOAD until too late #72

HaleTom opened this issue Oct 30, 2020 · 1 comment

Comments

@HaleTom
Copy link

HaleTom commented Oct 30, 2020

_zsh_nvm_auto_use will return early if nvm_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, before nvm, node, etc are run for the first time?

@ht55ght55
Copy link

ht55ght55 commented Feb 28, 2021

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** --------->

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants