Skip to content

Followup latest version of the tools using asdf

Posted on:October 10, 2022 at 01:07 PM

A Comic By by Monkey User about a Final patch in production

Disclaimer!: This post only talks about asdf .
afx is also quite new to me too and I don’t have enough experience to help you out, maybe you can let me know or point me in the correct direction if you find something and I will update it here.

Table of contents

Open Table of contents

Why this post

If I don’t care about the version of a tool just that I have the latest, what should I do? — rephrased ;)

Aashish

asdf install latest

Install latest stable version that begins with a given string.

asdf install latest:

However, I have not used it myself recently and earlier it did not work.

What do I use? a self developed shell script. (it probably does not work directly on mac) : update-asdf.sh.

#!/usr/bin/env bash
SCRIPT_PATH=$(dirname "$0")
echo "-- adding plugins --"
grep -v '^ *#' < "$SCRIPT_PATH/.tool-versions" | while IFS= read -r line
do
asdf plugin add "$(echo "$line" | awk '{print $1}')"
done
echo "-- updating plugins --"
asdf plugin update --all
echo "-- installing currently used plugin versions --"
asdf install
INTERACTIVE=yes
if [[ $# -eq 1 ]] && [[ "x${1}" = "x-n" ]] ; then
INTERACTIVE=no
fi
if [[ "${INTERACTIVE}" = "yes" ]] ; then
read -r -n 1 -p "Make all current versions global? [Y/y/anyCharacterToSkip] : " ANSWER
fi
echo ""
if [[ "${INTERACTIVE}" = "no" ]] || [[ "x${ANSWER,,}" = "xy" ]] ; then
while IFS= read -r line
do
plugin_name=$(echo "${line}" | awk '{print $1}')
plugin_version=$(echo "${line}" | awk '{print $2}')
asdf global ${plugin_name} ${plugin_version}
done < <(grep -v '^ *#' < "${SCRIPT_PATH}/.tool-versions" | awk 'NF > 0')
fi
sleep 1
if [[ "${INTERACTIVE}" = "yes" ]] ; then
read -r -n 1 -p "Check For Version Updates? [Y/y/anyCharacterToSkip] : " ANSWER
fi
echo ""
if [[ "${INTERACTIVE}" = "no" ]] || [[ "x${ANSWER,,}" = "xy" ]] ; then
echo "--- Update Notice! ----"
# shellcheck disable=SC2066
update_command="sed -i"
while IFS= read -r line
do
plugin_name=$(echo "${line}" | awk '{print $1}')
plugin_version=$(echo "${line}" | awk '{print $2}')
if [[ "x${plugin_name}" == "xjava" ]] ; then
some_latest_versions=$(asdf list all "${plugin_name}" 2>&1 | grep "temurin-17" | sed '/-/!{s/$/_/}' | sort -V | sed 's/_$//' | tail -3 | tr '\n' ' ')
the_latest_version=$(asdf list all "${plugin_name}" 2>&1 | grep "temurin-17" | sed '/-/!{s/$/_/}' | sort -V | sed 's/_$//' | tail -1)
else
some_latest_versions=$(asdf list all "${plugin_name}" 2>&1 | grep -i -v beta | grep -i -v alpha | grep -v '${{PACKAGE_VERSION}}' | grep -i -v rc | grep -i -v pre-dev | sed '/-/!{s/$/_/}' | sort -V | sed 's/_$//' | tail -3 | tr '\n' ' ')
the_latest_version=$(asdf list all "${plugin_name}" 2>&1 | grep -i -v beta | grep -i -v alpha | grep -v '${{PACKAGE_VERSION}}' | grep -i -v rc | grep -i -v pre-dev | sed '/-/!{s/$/_/}' | sort -V | sed 's/_$//' | tail -1)
fi
echo "'${plugin_name}' currently using '${plugin_version}', some newer versions : ${some_latest_versions}"
if [[ "x${plugin_version}" != "x${the_latest_version}" ]] ; then
echo "'${plugin_name}' Update using: sed -i '/${plugin_name}/s/${plugin_version}/${the_latest_version}/' .tool-versions"
update_command="$update_command -e '/${plugin_name}/s/${plugin_version}/${the_latest_version}/'"
fi
echo "--"
done < <(grep -v '^ *#' < "${SCRIPT_PATH}/.tool-versions" | awk 'NF > 0')
echo "-- Or all in one go --"
echo "$update_command .tool-versions"
echo "--- Disclaimer! Only Update if you have time to test! ---"
fi
view raw asdf-update.sh hosted with ❤ by GitHub

Let’s see it in action shall we?

This is what I use, and I know it’s a little rough around the edges but get’s the job done. What does it do?

  1. Reads the .tool-versions and and adds all the plugins for each listed tool. YMMV
  2. Updates all the Plugins (they are each their own git repo)
  3. Runs asdf install
  4. Asks if you want make all versions global. (just creates / appends / updates ${HOME}/.tool-versions)
  5. Checks each plugin for a newer version and show top three versions.
    • Some personal optimizations are applied, like for java only use temurin
    • Ignore some alpha / beta / pre-dev / dev / some error versions seens
  6. Then for each update show one line in place edit sed command to update individual tool
  7. Also, a consolidated sed to update all tools at once
  8. there is a update-asdf.sh -n flag that runs in non-interactively by saying yes but does not actually update any versions.

alternative option

There’s also an interesting use of the excellent fzf to update asdf tool versions

# Install one or more versions of specified language
# e.g. `vmi rust` # => fzf multimode, tab to mark, enter to install
# if no plugin is supplied (e.g. `vmi<CR>`), fzf will list them for you
# Mnemonic [V]ersion [M]anager [I]nstall
vmi() {
  local lang=${1}

  if [[ ! $lang ]]; then
    lang=$(asdf plugin-list | fzf)
  fi

  if [[ $lang ]]; then
    local versions=$(asdf list-all $lang | fzf --tac --no-sort --multi)
    if [[ $versions ]]; then
      for version in $(echo $versions);
      do; asdf install $lang $version; done;
    fi
  fi
}

In action

This too does not update the versions in the .tool-versions file, but probably is not too hard to add that in. This exercise is left for the reader (I’ve always wanted to say that)

A monkeyuser comic on backlogs

Extro

Pick one from above, maybe modify it to update the tool to the latest and then run asdf install schedule the run of the chosen method non-interactively and that should take you further until something breaks because of an update.

So that’s it, hope this helps!