mirror of
https://github.com/lukechilds/zsh-nvm.git
synced 2025-01-30 09:47:14 +08:00
Add revert command
This commit is contained in:
parent
781b46dede
commit
a7b8594684
@ -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…
Reference in New Issue
Block a user