From 8e5a901947c9463a2a5238d06d5ba44320e0f2fc Mon Sep 17 00:00:00 2001 From: dabruh <11458706-dabruh@users.noreply.gitlab.com> Date: Tue, 7 Jun 2022 11:50:20 +0200 Subject: [PATCH] Kubernetes context switcher. --- .local/bin/cx | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100755 .local/bin/cx diff --git a/.local/bin/cx b/.local/bin/cx new file mode 100755 index 0000000..91c900e --- /dev/null +++ b/.local/bin/cx @@ -0,0 +1,9 @@ +#!/bin/bash + +LAST=/tmp/last_kube_context +CURR="$(kubectl config current-context)" +[[ -z "$1" ]] && kubectl config get-contexts && exit +[ ! -f $LAST ] && echo "$CURR" >$LAST +[[ "$1" == "-" ]] && USE="$(cat $LAST)" || USE="$1" +[[ "$CURR" != "$USE" ]] && echo "$CURR" >$LAST +kubectl config use-context "$USE"