Last active
September 18, 2023 13:16
-
-
Save iTrooz/55c694bbe020415ea5c77b9eeb665304 to your computer and use it in GitHub Desktop.
kubeenv
This file contains 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
function kubeenv() { | |
DIR=$(realpath ~/.config/kube) | |
if [ $# -eq 0 ]; then | |
>&2 echo "$0: Please specify a config file or -l to list them" | |
return 1 | |
fi | |
if [[ "$1" = "-l" ]]; then | |
echo "Config files in $DIR :" | |
ls $DIR | |
return 0 | |
fi | |
if [ "${1:0:1}" = "/" ]; then # check if absolute path | |
filepath=$1 | |
else | |
filepath="$DIR/$1" | |
fi | |
if [ -f $filepath ]; then | |
export KUBECONFIG=$filepath | |
echo "$0: Success" | |
else | |
>&2 echo "$0: file $filepath doesn't exist" | |
return 1 | |
fi | |
} |
This file contains 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
# What is this | |
function used to set your KUBECONFIG variable to a config file easily. I prefer this rather than `kubectl config use-context` becauses it is dependnet to the current shell process, and so forces me to opt in a given config | |
# Installation | |
Simply put this function in your .zshrc, .bashrc, or similar | |
Then you can run `kubeenv <config file>` as a regular shell command | |
# Licence | |
CC0 / Public Domain |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment