Skip to content

Instantly share code, notes, and snippets.

@dudash
Last active April 13, 2021 20:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dudash/18570766c8071c09b65ab0620fc1d383 to your computer and use it in GitHub Desktop.
Save dudash/18570766c8071c09b65ab0620fc1d383 to your computer and use it in GitHub Desktop.
Flip between versions of the Knative CLI easily
#!/bin/bash
# Simple script to help configuring which kn CLI to use when you
# have a need to keep multiple versions and switch between them.
# Install and notes:
# 1. put this in /usr/local/bin and chmod +x
# 2. keep all the versions of kn in the /Applications directory
# 3. name kn executables with corresponding version - e.g. /Applications/kn-0.14.0
prompt="Please select an kn version:"
options=( $(ls /Applications/kn* | xargs -0) )
PS3="$prompt "
select opt in "${options[@]}" "Quit" ; do
if (( REPLY == 1 + ${#options[@]} )) ; then
exit
elif (( REPLY > 0 && REPLY <= ${#options[@]} )) ; then
echo "You picked $REPLY"
break
else
echo "Invalid option. Try another one."
fi
done
echo "Switching kn to version at $opt"
ln -sf $opt /usr/local/bin/kn
kn version
if test -z $BASH_VERSION; then
source <(kn completion bash)
echo "Autocompletion ON (bash)"
elif test -z $ZSH_VERSION; then
source <(kn completion zsh)
echo "Autocompletion ON (zsh)"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment