diff options
author | Christian Segundo | 2023-05-21 15:15:49 +0200 |
---|---|---|
committer | Christian Segundo | 2023-05-21 21:34:21 +0200 |
commit | 0d927a66dd793e15cd24294ab9f0a7c8b9953e9c (patch) | |
tree | 7ce1ecb067d0b51eb237ffed2acd9b2e939d32a8 /kontext.in | |
parent | ada36c86a256275fab8400f155ded2815db3836b (diff) | |
download | kontext-0d927a66dd793e15cd24294ab9f0a7c8b9953e9c.tar.gz |
Add kontext1.0.0
Diffstat (limited to 'kontext.in')
-rwxr-xr-x | kontext.in | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/kontext.in b/kontext.in new file mode 100755 index 0000000..a16798a --- /dev/null +++ b/kontext.in @@ -0,0 +1,51 @@ +#!@ENV_ABSOLUTE_PATH@ bash + +[[ "${BASH_SOURCE[0]}" != "${0}" ]] || { >&2 cat <<EOF +Warning: kontext is not being sourced, add this alias to your shell: + alias kontext="source kontext" +EOF +exit 1; } + +kontext_func () { + local TEMP + TEMP=$(@GNU_GETOPT@ -o hn: --long help,namespace: -n 'kontext' -- "$@") + eval set -- "$TEMP" + + local HELP=false + local NAMESPACE="" + local CTX="" + + while true; do + case "$1" in + -h | --help ) HELP=true; shift ;; + -n | --namespace ) NAMESPACE="$2"; shift 2 ;; + -- ) CTX="$2"; shift; break ;; + * ) break ;; + esac + done + + if [ -z "$CTX" ] && [ -n "$NAMESPACE" ]; then + CTX=$(kubectl config current-context) + fi + + if [ -z "$CTX" ] || [ "$HELP" = true ]; then + cat <<-EOF +Usage: + kontext [-h|--help]" + Show this text. + kontext [-n|--namespace <namespace>] [<context>]" + Switch to the given namespace and context. + +More information may be found in the kontext(1) man page. +EOF + return 1 + else + TMP_KUBECONFIG=$(mktemp -t kubeconfig-XXXXXX) + kubectl config view --raw > "$TMP_KUBECONFIG" + export KUBECONFIG="$TMP_KUBECONFIG" + kubectl config use-context "$CTX" && \ + kubectl config set-context --current --namespace="$NAMESPACE" + fi +} + +kontext_func "$@" |