#!/bin/bash
# Gather constant vars
ASDF_PLUGIN=""
ASDF_NEW_PLUGIN_VERSION=""
# Declare script fuctions
# Delete other plugin versions
delete_other_plugin_versions ()
{
for plugin_version in $(asdf list $ASDF_PLUGIN)
do
if [[ $plugin_version != $ASDF_NEW_PLUGIN_VERSION ]]
then
echo -e "delete \e[1;32m$plugin_version\e[0m version of \e[1;34m$ASDF_PLUGIN\e[0m"
asdf uninstall $ASDF_PLUGIN $plugin_version
fi
done
}
# Delete other plugin versions menu
delete_other_plugin_versions_menu ()
{
while true; do
read -p "Do you wish delete other $ASDF_PLUGIN versions (y/n)? " yn
case $yn in
[Yy]* ) delete_other_plugin_versions; break;;
[Nn]* ) break;;
* ) echo -e "Please answer \e[1;31myes\e[0m or \e[1;31mno\e[0m. ";;
esac
done
}
# set plugin name
set_plugin_name ()
{
read -p "Type asdf plugin name: " ASDF_PLUGIN
if [[ $ASDF_PLUGIN = "" ]]
then
echo "Plugin name is not be enpty"
exit
fi
}
# read asdf installed plugins and versions
asdf current
echo ""
# set plugin name
set_plugin_name
echo ""
# get plugin versions
echo -e "List all \e[1;34m$ASDF_PLUGIN\e[0m versions:"
asdf list-all $ASDF_PLUGIN
echo ""
echo -e "installed version(s) of \e[1;34m$ASDF_PLUGIN\e[0m:"
asdf list $ASDF_PLUGIN
echo ""
echo -e "current version \e[1;34m$ASDF_PLUGIN\e[0m is: \e[1;32m$(asdf current $ASDF_PLUGIN)\e[0m"
echo ""
# set new plugin version
read -p "Type NEW $ASDF_PLUGIN version: " ASDF_NEW_PLUGIN_VERSION
echo ""
# delete other plugin versions menu
delete_other_plugin_versions_menu
echo ""
# install & set global new plugin version
asdf install $ASDF_PLUGIN $ASDF_NEW_PLUGIN_VERSION
asdf global $ASDF_PLUGIN $ASDF_NEW_PLUGIN_VERSION
echo ""
# report user about current state of plugin versions
echo -e "installed version(s) of \e[1;34m$ASDF_PLUGIN\e[0m:"
asdf list $ASDF_PLUGIN
echo ""
echo -e "current version \e[1;34m$ASDF_PLUGIN\e[0m is: \e[1;32m$(asdf current $ASDF_PLUGIN)\e[0m"
echo ""