aboutsummaryrefslogtreecommitdiff
path: root/kontext.in
diff options
context:
space:
mode:
authorChristian Segundo2023-05-21 15:15:49 +0200
committerChristian Segundo2023-05-21 21:34:21 +0200
commit0d927a66dd793e15cd24294ab9f0a7c8b9953e9c (patch)
tree7ce1ecb067d0b51eb237ffed2acd9b2e939d32a8 /kontext.in
parentada36c86a256275fab8400f155ded2815db3836b (diff)
downloadkontext-10d63f3ce11637e712ba3f3b0f69ad8e3df16ee0.tar.gz
Add kontext1.0.0
Diffstat (limited to 'kontext.in')
-rwxr-xr-xkontext.in51
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 "$@"