Skip to content

Instantly share code, notes, and snippets.

@laidbackware
Created January 7, 2022 14:32
Show Gist options
  • Save laidbackware/234b1fa603df0d8864f34edd63633f88 to your computer and use it in GitHub Desktop.
Save laidbackware/234b1fa603df0d8864f34edd63633f88 to your computer and use it in GitHub Desktop.
Bash function to update an ASDF plugin
# This file must be sourced from your shell
function asdfu() {
product_name=${1:-}
if [ -z $product_name ]; then
>&2 echo "You must pass in a product name. E.g. asdfu kubectl"
return 1
fi
asdf plugin add $product_name
ret_code=$?
if [ $ret_code -eq 2 ]; then
asdf plugin update $product_name || return 1
elif [ $ret_code -ne 2 ] && [ $ret_code -ne 0 ]; then
>&2 echo "ERROR: Aborting"
return 1
fi
asdf install $product_name latest
if [ $? -ne 0 ]; then
>&2 echo "ERROR: Aborting"
return 1
fi
latest_version="$(asdf list $product_name | sort -r | head -n 1 | xargs)" || return 1
asdf global $product_name $latest_version
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment