Skip to content

Instantly share code, notes, and snippets.

@cmosguy
Forked from Ilyes512/nvm_install.sh
Last active August 29, 2015 14:00
Show Gist options
  • Save cmosguy/0b4ff5ff5e8396fc136e to your computer and use it in GitHub Desktop.
Save cmosguy/0b4ff5ff5e8396fc136e to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
NVM_DIR="$HOME/.nvm"
if ! hash git 2>/dev/null; then
echo >&2 "!!! You need to install git"
exit 1
fi
if [ -d "$NVM_DIR" ]; then
echo ">>> NVM is already installed in $NVM_DIR, trying to update"
echo -ne "\r=> "
cd $NVM_DIR && git pull
else
# Cloning to $NVM_DIR
git clone https://github.com/creationix/nvm.git $NVM_DIR
fi
PROFILE="$HOME/.profile"
ZSHRC="$HOME/.zshrc"
SOURCE_STR="\n# This loads NVM\n[[ -s $HOME/.nvm/nvm.sh ]] && . $HOME/.nvm/nvm.sh"
# Append NVM script to ~/.profile
if ! grep -qsc 'nvm.sh' $PROFILE; then
echo ">>> Appending source string to $PROFILE"
echo $SOURCE_STR >> "$PROFILE"
else
echo ">>> Source string already in $PROFILE"
fi
# Check if .zshrc exist
if [ -f "$ZSHRC" ]; then
# Append NVM script to ~/.zshrc
if ! grep -qsc 'nvm.sh' $ZSHRC; then
echo ">>> Appending source string to $ZSHRC"
echo $SOURCE_STR >> "$ZSHRC"
else
echo ">>> Source string already in $ZSHRC"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment