This commit is contained in:
Philipp Schmitt 2025-01-23 12:07:06 -05:00 committed by GitHub
commit 814caa4ced
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

10
kubectx
View File

@ -108,14 +108,20 @@ save_context() {
}
switch_context() {
$KUBECTL config use-context "${1}"
if ! $KUBECTL config use-context "${1}"; then
if [[ -t 1 && -z "${KUBECTX_IGNORE_FZF:-}" && "$(type fzf &>/dev/null; echo $?)" -eq 0 ]]; then
choose_context_interactive "${1}"
else
return 1
fi
fi
}
choose_context_interactive() {
local choice
choice="$(_KUBECTX_FORCE_COLOR=1 \
FZF_DEFAULT_COMMAND="${SELF_CMD}" \
fzf --ansi --no-preview || true)"
fzf --ansi --no-preview --query "${1:-}" --select-1 || true)"
if [[ -z "${choice}" ]]; then
echo 2>&1 "error: you did not choose any of the options"
exit 1