Extend nvm function for upgrade command

This commit is contained in:
Luke Childs 2016-07-24 19:28:51 +01:00
parent 0795cfebbb
commit 21bfbbf3c8

View File

@ -1,5 +1,11 @@
[[ -z "$NVM_DIR" ]] && NVM_DIR="$HOME/.nvm"
_zsh_nvm_rename_function() {
test -n "$(declare -f $1)" || return
eval "${_/$1/$2}"
unset -f $1
}
_zsh_nvm_has() {
type "$1" > /dev/null 2>&1
}
@ -25,6 +31,9 @@ _zsh_nvm_install() {
}
nvm_update() {
echo 'Deprecated, please use `nvm upgrade`'
}
_zsh_nvm_upgrade() {
local installed_version=$(cd "$NVM_DIR" && git describe --tags)
echo "Installed version is $installed_version"
echo "Checking latest version of nvm..."
@ -41,5 +50,24 @@ nvm_update() {
# Install nvm if it isn't already installed
[[ ! -f "$NVM_DIR/nvm.sh" ]] && _zsh_nvm_install
# If nvm is installed, source it
[[ -f "$NVM_DIR/nvm.sh" ]] && source "$NVM_DIR/nvm.sh"
# If nvm is installed
if [[ -f "$NVM_DIR/nvm.sh" ]]; then
# Source nvm
source "$NVM_DIR/nvm.sh"
# Rename main nvm function
_zsh_nvm_rename_function nvm _zsh_nvm_nvm
# Wrap nvm in our own function
nvm() {
case $1 in
'upgrade')
_zsh_nvm_upgrade
;;
*)
_zsh_nvm_nvm "$@"
;;
esac
}
fi