Skip to content

Instantly share code, notes, and snippets.

@mrWinston
Created May 5, 2023 08:06
Show Gist options
  • Save mrWinston/9fc05ad21a8b9da48f9c87e6f5406042 to your computer and use it in GitHub Desktop.
Save mrWinston/9fc05ad21a8b9da48f9c87e6f5406042 to your computer and use it in GitHub Desktop.
Update all installed asdf plugins
#!/bin/bash
# either run this script to trigger the update, or copy the function below to your .bash/.zshrc and run with `asdfUpdateAll`
# the function also supports `--yes` to disable confirmation for updating a plugin.
asdfUpdateAll() {
if ! asdf > /dev/null; then
echo "Something went wrong when running 'asdf'"
return 1
fi
if [[ $1 == "-h" || $1 == "--help" ]]; then
echo -e "usage: $0 [OPTION]..."
echo -e "Update all installed asdf plugins."
echo -e ""
echo -e " -y, --yes \t don't ask for confirmation when updating a plugin"
return 0
fi
if [[ $1 == "-y" || $1 == "--yes" ]]; then
assumeyes="yes"
fi
for plugin in $(asdf plugin list); do
echo -e "\n------------------\n"
echo -e "${plugin}:"
latestVersion=$(asdf latest "$plugin")
currentVersion=$(asdf current "$plugin" | awk '{print $2}')
if [[ "$currentVersion" == "$latestVersion" ]]; then
echo -e "\tAlready up to date. Skipping..."
continue
fi
if [[ -z "$assumeyes" ]]; then
echo -en "\tUpdate $plugin to version ${latestVersion}? [y/n]: "
read -r yn
if [ "$yn" != "y" ]; then
echo "Skipping $plugin..."
continue
fi
fi
echo -e "\tUpdating $plugin to version ${latestVersion}..."
asdf install "${plugin}" "${latestVersion}"
asdf global "${plugin}" "${latestVersion}"
done
}
asdfUpdateAll
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment