Skip to content

Instantly share code, notes, and snippets.

@developer-guy
Last active April 22, 2024 02:06
Show Gist options
  • Save developer-guy/4de4e2ff2eaa31633a0fef719c92eada to your computer and use it in GitHub Desktop.
Save developer-guy/4de4e2ff2eaa31633a0fef719c92eada to your computer and use it in GitHub Desktop.
Update asdf plugins to their latest versions if necessary
#!/usr/bin/env sh
function update() {
for i in `asdf plugin list`
do
CURRENT_VERSION=`asdf current $i | awk '{print $2}'`
LATEST_VERSION=`asdf latest $i`
echo "Working with $i current version $CURRENT_VERSION but latest version is $LATEST_VERSION"
if [[ $(semver_check $LATEST_VERSION $CURRENT_VERSION) -lt 0 ]]; then
echo "Needs to update"
asdf install $i $LATEST_VERSION
echo "Prearing global value of $i is $LATEST_VERSION"
asdf global $i $LATEST_VERSION
else
echo "No need to update $i."
fi
done
}
function semver_check() {
# sort low->high then pick the last one (highest)
local HV; HV=$(echo -e "$1\n$2" |sort -V |tail -1)
# They're not the same and $1 is not the high version = -1
[[ "$1" != "$2" && "$1" != "$HV" ]] && echo -1 && return
# 0 = they're the same; 1 = not the same
[[ "$1" == "$2" ]]; echo $?
}
function main() {
update
}
main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment