Last active
February 5, 2025 04:22
-
-
Save saamalik/76d65b39f2622c11879e9d133c5e1505 to your computer and use it in GitHub Desktop.
Speedy K8s switching with kctx & klctx
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
# add to your shell startup script (e.g: $HOME/.bashrc). | |
# install [fzf](https://github.com/junegunn/fzf) | |
# e.g: brew install fzf | |
kctx() { | |
( | |
cd ~/.kube/ || exit 1 | |
# shellcheck disable=SC2012 | |
KUBE=$(ls kube-* | fzf) | |
[[ -n "$KUBE" ]] && ln -sf "$KUBE" config | |
) | |
} | |
klctx() { | |
# shellcheck disable=SC1083 | |
local SEARCH="${1:-$HOME/Downloads}" | |
[[ "$1" == "-" ]] && SEARCH="$HOME/.kube" | |
local KUBE=$(ls "$SEARCH" -p -t | grep -v / | fzf) | |
if [[ -n "$KUBE" ]]; then | |
export KUBECONFIG="${SEARCH%/}/$KUBE" | |
fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment