Last active
March 18, 2021 20:24
-
-
Save dudash/31386b27b7c7dc3513d1f84d0397e4cf to your computer and use it in GitHub Desktop.
Flip between versions of the OpenShift CLI easily
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
| #!/bin/bash | |
| # Simple script to help configuring which oc 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 oc in the /Applications directory | |
| # 3. name oc executables with corresponding version - e.g. /Applications/oc-4.5.0 | |
| prompt="Please select an oc version:" | |
| options=( $(ls /Applications/oc* | 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 oc to version at $opt" | |
| ln -sf $opt /usr/local/bin/oc | |
| oc version | |
| if test -z $BASH_VERSION; then | |
| source <(oc completion bash) | |
| echo "Autocompletion ON (bash)" | |
| elif test -z $ZSH_VERSION; then | |
| source <(oc 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