zsh-nvm icon indicating copy to clipboard operation
zsh-nvm copied to clipboard

Allow use of NVM_AUTO_USE alongside NVM_LAZY_LOAD on init

Open runofthemill opened this issue 4 years ago • 9 comments

Right now, NVM_AUTO_USE=true will not get applied on the initial call of nvm/npm/node/yarn, and only work on subsequent session directory changes. This PR makes NVM_AUTO_USE=true go into effect at the first invocation when NVM_LAZY_LOAD=true.

Note - I'm good enough at tinkering in shell scripts, but totally could be doing something dumb here! Thanks for taking a look and making a great plugin!

runofthemill avatar Jul 23 '19 00:07 runofthemill

Thanks, I tried ~and failed~ to write an urchin test for this, ~but~ it's working for me locally!

amirdt22 avatar Jul 28 '19 22:07 amirdt22

Whoops! I forgot about tests, didn't see the test failed until just now. Thanks @amirdt22 - I'll take a look at your PR :)

runofthemill avatar Jul 29 '19 17:07 runofthemill

@amirdt22 @lukechilds any thoughts on why the tests are failing? Running the tests locally with urchin fails on NVM_LAZY_LOAD && NVM_NO_USE, but every other test passes.

runofthemill avatar Sep 27 '19 22:09 runofthemill

@runofthemill, first of all, thank you a lot man for this PR but I have a weird issue maybe it's the reason for the failing tests or something

my prompt shows the node version and strangely when I navigate to project has .nvmrc it shows the message as it already loaded

but I had to run any command first so it runs properly and shows the real node version

snowflake in saleor on  master is 📦 v0.0.0 via ⬢ Found '/Users/snowflake/Playground/saleor/.nvmrc' with version <10.15.2>
Now using node v10.15.2 (npm v6.4.1)
v10.15.2 on 🐳 v19.03.8 via 🐍 system
[I] ➜ node -v
Found '/Users/snowflake/Playground/saleor/.nvmrc' with version <10.15.2>
Now using node v10.15.2 (npm v6.4.1)
v10.15.2

snowflake in saleor on  master is 📦 v0.0.0 via ⬢ v10.15.2 on 🐳 v19.03.8 via 🐍 system took 3s
[I] ➜

MuhmdRaouf avatar Mar 22 '20 01:03 MuhmdRaouf

@MuhmdRaouf you're talking about how it's showing the message inside your prompt? how is that section of your prompt defined?

runofthemill avatar Apr 01 '20 17:04 runofthemill

@runofthemill I am using Zsh SpaceShip Theme and it shows the current node version, whenever I move to the folder contain .nvmrc file instead of showing node version it shows,

Found '/Users/snowflake/Playground/saleor/.nvmrc' with version <10.15.2>
Now using node v10.15.2 (npm v6.4.1)
v10.15.2

instead of node version.

MuhmdRaouf avatar Apr 01 '20 17:04 MuhmdRaouf

@MuhmdRaouf I just checked and looks like the theme would need to add some logic here:

https://github.com/denysdovhan/spaceship-prompt/blob/2796da9d5c4a6af7a8255315aa5eeae4aa929679/sections/node.zsh#L31-L33

In iTerm2 I use this to conditionally set the node version in the app status bar, you could probably use something similar in the theme:


function set_node_version() {
  if (type _zsh_nvm_nvm &>/dev/null); then
    echo $(nvm current)
  else
    echo "unset"
  fi
}

runofthemill avatar May 15 '20 03:05 runofthemill

@lukechilds I finally got tests to pass (yay escaping things!) - would love your thoughts on the PR whenever you get a chance!

runofthemill avatar May 15 '20 15:05 runofthemill

This is what you should do here:

[[ "$NVM_AUTO_USE" == true ]] && _zsh_nvm_auto_use The hooks are already loaded, you just need to run _zsh_nvm_auto_use after loading nvm

nicoladefranceschi avatar Nov 02 '20 12:11 nicoladefranceschi