From a7b8594684547f5da3ee728c2631b7371ae6a5c0 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Tue, 26 Jul 2016 23:20:32 +0100 Subject: [PATCH] Add revert command --- zsh-nvm.plugin.zsh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/zsh-nvm.plugin.zsh b/zsh-nvm.plugin.zsh index 5600d76..a99d5ce 100644 --- a/zsh-nvm.plugin.zsh +++ b/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