-
-
Save gfguthrie/9f9e3908745694c81330c01111a9d642 to your computer and use it in GitHub Desktop.
# normal brew nvm shell config lines minus the 2nd one | |
# lazy loading the bash completions does not save us meaningful shell startup time, so we won't do it | |
export NVM_DIR="$HOME/.nvm" | |
[ -s "/usr/local/opt/nvm/etc/bash_completion" ] && . "/usr/local/opt/nvm/etc/bash_completion" # This loads nvm bash_completion | |
# add our default nvm node (`nvm alias default 10.16.0`) to path without loading nvm | |
export PATH="$NVM_DIR/versions/node/v$(<$NVM_DIR/alias/default)/bin:$PATH" | |
# alias `nvm` to this one liner lazy load of the normal nvm script | |
alias nvm="unalias nvm; [ -s "/usr/local/opt/nvm/nvm.sh" ] && . "/usr/local/opt/nvm/nvm.sh"; nvm $@" |
@yo1dog your solution (mac) seems to create an infine loop for me
You running with BASH or ZSH? I found that BASH does not allow for local
outside of functions which causes an error and an infinite loop as DEFAULT_NODE_VER
is empty and [ -s ... ]
on a directory always returns 0.
I updated the script to remove local
so it should work under BASH as well.
@LeonardoGentile if you
echo $PATH
, is the path to node in there correctly? If you copied my example exactly, but then use thev
in the version you make default, it probably is not correct. You can specify the version without thev
, modify the script to not add it, or use the first example @yo1dog posted that takes care of it either way.
That was it 👍
@yo1dog your solution (mac) seems to create an infine loop for me
You running with BASH or ZSH? I found that BASH does not allow for
local
outside of functions which causes an error and an infinite loop asDEFAULT_NODE_VER
is empty and[ -s ... ]
on a directory always returns 0.I updated the script to remove
local
so it should work under BASH as well.
On bash, that why 👍 thanks
Works great, thanks! It would make it even clearer if you made sure to add comments about:
- Running
nvm alias default [preffered node-version]
- Changing
"/usr/local/opt/nvm/nvm.sh"
to your localnvm.sh
location
Worked just fine on MacOS and zsh 👍 . One small caveat I noticed by using this is that you cannot run which nvm
anymore, it will echo the executable output instead of returning the bin location.
@LeonardoGentile if you
echo $PATH
, is the path to node in there correctly? If you copied my example exactly, but then use thev
in the version you make default, it probably is not correct. You can specify the version without thev
, modify the script to not add it, or use the first example @yo1dog posted that takes care of it either way.