Skip to content

Instantly share code, notes, and snippets.

@freyes
Created January 31, 2023 13:52
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 freyes/dc2cc8be8fd4c80f2e8e407eea6eb401 to your computer and use it in GitHub Desktop.
Save freyes/dc2cc8be8fd4c80f2e8e407eea6eb401 to your computer and use it in GitHub Desktop.

Switch charmcraft aliases:

Usage examples:

charmcraft-workon 1.5
charmcraft-workon 2.0
#!/bin/bash -e
VERSION=${1:-""}
if [ "x${VERSION}" == "x" ]; then
echo -e "\nCurrent: $(file /snap/bin/charmcraft)"
echo -e "\nUsage example:"
echo " charmcraft-workon 1.5"
exit 1
fi
SNAP_SUFIX=$(echo $VERSION | sed 's/\./pt/')
TARGET=charmcraft_${SNAP_SUFIX}
if [ -f /snap/bin/${TARGET} ]; then
sudo snap unalias charmcraft
sudo snap alias ${TARGET} charmcraft
else
echo "The requested version doesn't exist, please install it running:"
echo " sudo snap install --classic charmcraft_${SNAP_SUFIX}"
exit 2
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment