You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.4 KiB

[[ -z "$NVM_DIR" ]] && NVM_DIR="$HOME/.nvm"
8 years ago
_zsh_nvm_has() {
type "$1" > /dev/null 2>&1
}
_zsh_nvm_get() {
if _zsh_nvm_has "curl"; then
curl --silent "$1"
elif _zsh_nvm_has "wget"; then
wget --quiet --output-document - "$1"
fi
}
_zsh_nvm_latest_release_tag() {
_zsh_nvm_get "https://api.github.com/repos/creationix/nvm/releases/latest" | # Get latest release from GitHub api
grep '"tag_name":' | # Get tag line
sed -E 's/.*"([^"]+)".*/\1/' # Pluck JSON value
}
_zsh_nvm_install() {
echo "Installing nvm..."
git clone https://github.com/creationix/nvm.git "$NVM_DIR"
$(cd "$NVM_DIR" && git checkout --quiet "$(_zsh_nvm_latest_release_tag)")
}
8 years ago
nvm_update() {
local installed_version=$(cd "$NVM_DIR" && git describe --tags)
echo "Installed version is $installed_version"
echo "Checking latest version of nvm..."
local latest_version=$(_zsh_nvm_latest_release_tag)
if [[ "$installed_version" = "$latest_version" ]]; then
echo "You're already up to date"
else
echo "Updating to $latest_version..."
$(cd "$NVM_DIR" && git fetch --quiet && git checkout "$latest_version")
source "$NVM_DIR/nvm.sh"
fi
}
8 years ago
# Install nvm if it isn't already installed
[[ ! -f "$NVM_DIR/nvm.sh" ]] && _zsh_nvm_install
8 years ago
# If nvm is installed, source it
[[ -f "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh"