lukechilds / zsh-nvm

Zsh plugin for installing, updating and loading nvm
MIT License
2.24k stars 113 forks source link

Allow use of NVM_AUTO_USE alongside NVM_LAZY_LOAD on init #55

Open runofthemill opened 5 years ago

runofthemill commented 5 years ago

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!

amirdt22 commented 5 years ago

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

runofthemill commented 5 years ago

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 commented 5 years ago

@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.

MuhmdRaouf commented 4 years ago

@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] ➜
runofthemill commented 4 years ago

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

MuhmdRaouf commented 4 years ago

@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.

runofthemill commented 4 years ago

@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 commented 4 years ago

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

nicoladefranceschi commented 4 years ago

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