Skip to content

Instantly share code, notes, and snippets.

@saamalik
Last active July 12, 2024 16:14
Show Gist options
  • Save saamalik/76d65b39f2622c11879e9d133c5e1505 to your computer and use it in GitHub Desktop.
Save saamalik/76d65b39f2622c11879e9d133c5e1505 to your computer and use it in GitHub Desktop.
Speedy K8s switching with kctx & klctx
# 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