Last active
February 16, 2023 18:30
-
-
Save davidegreenwald/e72f8082998901e01768c056ae1d950e to your computer and use it in GitHub Desktop.
asdf automatic patch updates
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# asdf does not have brew-like update functionality and "latest" cannot be used in a .tool-versions file | |
# making keeping up with new semantic versions a manual and laborious process | |
# This shell profile function automates this away and will patch update all local .tool-versions packages | |
# it could be refactored to apply globally or use flags to apply to a selected location | |
asdf_patch () { | |
if [ -f ./.tool-versions ]; then | |
# ensure .tool-versions has a closing newline or bash will skip the last app | |
if [ ! "$(cat .tool-versions | tail -c 1)" = "" ]; then echo "" >> .tool-versions; fi | |
while read -r LINE; | |
do | |
APP=$(echo ${LINE} | cut -d ' ' -f 1) | |
MINOR_VERSION=$(echo ${LINE} | cut -d ' ' -f 2 | cut -d '.' -f 1-2) | |
# Install the latest patch version for the project minor versions | |
asdf install ${APP} latest:${MINOR_VERSION} | |
# update the local .tool-versions file to use the patch versions | |
# they have to be installed before "latest" can be applied to a file | |
asdf local ${APP} latest:${MINOR_VERSION} | |
done < .tool-versions | |
else | |
echo "No .tool-versions available to update" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment