Browse Source

Add revert command

pull/5/head
Luke Childs 9 years ago
parent
commit
a7b8594684
  1. 24
      zsh-nvm.plugin.zsh

24
zsh-nvm.plugin.zsh

@ -46,6 +46,9 @@ _zsh_nvm_load() {
'upgrade')
_zsh_nvm_upgrade
;;
'revert')
_zsh_nvm_revert
;;
*)
_zsh_nvm_nvm "$@"
;;
@ -79,6 +82,27 @@ _zsh_nvm_upgrade() {
fi
}
_zsh_nvm_previous_version() {
cat "$ZSH_NVM_DIR/previous_version" 2>/dev/null
}
_zsh_nvm_revert() {
local previous_version="$(_zsh_nvm_previous_version)"
if [[ $previous_version ]]; then
local installed_version=$(cd "$NVM_DIR" && git describe --tags)
if [[ "$installed_version" = "$previous_version" ]]; then
echo "Already reverted to $installed_version"
return
fi
echo "Installed version is $installed_version"
echo "Reverting to $previous_version..."
$(cd "$NVM_DIR" && git checkout "$previous_version")
_zsh_nvm_load
else
echo "No previous version found"
fi
}
# Install nvm if it isn't already installed
[[ ! -f "$NVM_DIR/nvm.sh" ]] && _zsh_nvm_install

Loading…
Cancel
Save