Skip to content

Instantly share code, notes, and snippets.

@kkirsche
Last active July 11, 2023 15:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkirsche/8a8288bbff5c09a6bb900f2356f2748e to your computer and use it in GitHub Desktop.
Save kkirsche/8a8288bbff5c09a6bb900f2356f2748e to your computer and use it in GitHub Desktop.
ASDF Auto Updater
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
function version { echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }'; }
if ! command -v jq &> /dev/null
then
echo "jq could not be found"
echo "Please install this via 'brew install jq'"
else
for PLUGIN in $(asdf plugin list); do
VERSIONS=$(asdf list "${PLUGIN}")
VERSION_COUNT=$(echo "${VERSIONS}" | wc -l)
if [[ "${VERSION_COUNT}" -gt 1 ]]; then
echo "${PLUGIN} has multiple versions installed, skipping..."
continue
elif [[ "${VERSION_COUNT}" -eq 0 ]]; then
echo "${PLUGIN} has no versions installed, skipping..."
continue
fi
CURRENT=$(echo "${VERSIONS}" | tr -d '[:space:]*')
if [[ "${PLUGIN}" = "nodejs" ]]; then
CONSTRAINT=$(curl --silent "https://nodejs.org/download/release/index.json" | jq '.[] | select(.lts).version' | tr -d '"v' | sort -n | tail -n 1 | tr -d '[:space:]')
LATEST=$(asdf latest "${PLUGIN}" "${CONSTRAINT}")
else
LATEST=$(asdf latest "${PLUGIN}")
fi
if [[ $(version "${LATEST}") -gt $(version "${CURRENT}") ]]; then
echo "Installling ${PLUGIN} version: ${LATEST}..."
asdf install "${PLUGIN}" "${LATEST}"
echo "Setting global version of ${PLUGIN}: ${LATEST}..."
asdf global "${PLUGIN}" "${LATEST}"
echo "Removing previous version of ${PLUGIN}: ${CURRENT}..."
asdf uninstall "${PLUGIN}" "${CURRENT}"
echo "Reshimming ${PLUGIN}"
asdf reshim "${PLUGIN}"
else
echo "No asdf ${PLUGIN} langauge updates"
fi
done
fi
#!/usr/bin/env bash
set -eo pipefail
IFS=$'\n\t'
# Prezto
## https://github.com/sorin-ionescu/prezto#updating
pushd . >/dev/null
cd ~/.zprezto
git stash push --quiet
zprezto-update
git stash pop --quiet
popd
# Homebrew
## https://docs.brew.sh/FAQ#how-do-i-update-my-local-packages
brew update
brew upgrade
## we don't use --greedy because we want auto-updating apps to update themselves
## rather than be forced to upgrade via replacement
brew upgrade --cask
brew cleanup
# Bat
## https://github.com/sharkdp/bat#adding-new-syntaxes--language-definitions
bat cache --clear
bat cache --build
# Ruby
gem update
# ASDF
asdf plugin update --all
asdf-update-all # warning, this still breaks when installing from Python. That honestly needs to be rewritten in shell
# Python
python -m pip list --format=columns -o
# NodeJS
npm outdated --location=global --depth=0
# Final step because we want to reshim the updated packages / langauges
asdf reshim
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment