Skip to content

Instantly share code, notes, and snippets.

@developer-guy
Last active April 22, 2024 02:06
Show Gist options
  • Select an option

  • Save developer-guy/4de4e2ff2eaa31633a0fef719c92eada to your computer and use it in GitHub Desktop.

Select an option

Save developer-guy/4de4e2ff2eaa31633a0fef719c92eada to your computer and use it in GitHub Desktop.

Revisions

  1. developer-guy revised this gist Mar 14, 2021. No changes.
  2. developer-guy created this gist Mar 14, 2021.
    33 changes: 33 additions & 0 deletions update-asdf-plugins.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    #!/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