Created
September 27, 2019 22:02
-
-
Save gfguthrie/9f9e3908745694c81330c01111a9d642 to your computer and use it in GitHub Desktop.
Lazy Load Homebrew NVM but still have default aliased Node in PATH
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 $@" |
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.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Works great, thanks! It would make it even clearer if you made sure to add comments about:
nvm alias default [preffered node-version]
"/usr/local/opt/nvm/nvm.sh"
to your localnvm.sh
location