Skip to content

Instantly share code, notes, and snippets.

@Alex0007
Last active October 19, 2015 10:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Alex0007/a9a816865f502036cd90 to your computer and use it in GitHub Desktop.
Save Alex0007/a9a816865f502036cd90 to your computer and use it in GitHub Desktop.
nvm non-blocking sourcing
# Replace following lines
export NVM_DIR="/home/USERNAME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
init_nvm()
{
bin=$(echo $1 | awk '{print $1}') # get first word from command string
if [[ -z $NVM_DIR ]] && [[ ! `command -v $bin` ]]; then # if not already inited and no such binary found
export NVM_DIR="/home/USERNAME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
fi
}
preexec_functions+=(init_nvm)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment