mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-09-02 09:05:11 +00:00
Show color in interactive mode (#109)
This patch introduces an internal _KUBECTX_FORCE_COLOR environment variable that overrides color output decision. With this, fzf output shows the color indicators for ctx/ns and choosing the option with the color works without any extra handling. Fixes #89. Fixes #98.
This commit is contained in:
14
kubectx
14
kubectx
@@ -69,8 +69,14 @@ list_contexts() {
|
|||||||
cur_ctx_bg=${KUBECTX_CURRENT_BGCOLOR:-$darkbg}
|
cur_ctx_bg=${KUBECTX_CURRENT_BGCOLOR:-$darkbg}
|
||||||
|
|
||||||
for c in $ctx_list; do
|
for c in $ctx_list; do
|
||||||
if [[ -t 1 && -z "${NO_COLOR:-}" && "${c}" = "${cur}" ]]; then
|
if [[ -n "${_KUBECTX_FORCE_COLOR:-}" || \
|
||||||
echo "${cur_ctx_bg}${cur_ctx_fg}${c}${normal}"
|
-t 1 && -z "${NO_COLOR:-}" ]]; then
|
||||||
|
# colored output mode
|
||||||
|
if [[ "${c}" = "${cur}" ]]; then
|
||||||
|
echo "${cur_ctx_bg}${cur_ctx_fg}${c}${normal}"
|
||||||
|
else
|
||||||
|
echo "${c}"
|
||||||
|
fi
|
||||||
else
|
else
|
||||||
echo "${c}"
|
echo "${c}"
|
||||||
fi
|
fi
|
||||||
@@ -98,7 +104,9 @@ switch_context() {
|
|||||||
|
|
||||||
choose_context_interactive() {
|
choose_context_interactive() {
|
||||||
local choice
|
local choice
|
||||||
choice="$(FZF_DEFAULT_COMMAND="${SELF_CMD}" fzf --ansi || true)"
|
choice="$(_KUBECTX_FORCE_COLOR=1 \
|
||||||
|
FZF_DEFAULT_COMMAND="${SELF_CMD}" \
|
||||||
|
fzf --ansi || true)"
|
||||||
if [[ -z "${choice}" ]]; then
|
if [[ -z "${choice}" ]]; then
|
||||||
echo 2>&1 "error: you did not choose any of the options"
|
echo 2>&1 "error: you did not choose any of the options"
|
||||||
exit 1
|
exit 1
|
||||||
|
12
kubens
12
kubens
@@ -104,7 +104,9 @@ choose_namespace_interactive() {
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
local choice
|
local choice
|
||||||
choice="$(FZF_DEFAULT_COMMAND="${SELF_CMD}" fzf --ansi || true)"
|
choice="$(_KUBECTX_FORCE_COLOR=1 \
|
||||||
|
FZF_DEFAULT_COMMAND="${SELF_CMD}" \
|
||||||
|
fzf --ansi || true)"
|
||||||
if [[ -z "${choice}" ]]; then
|
if [[ -z "${choice}" ]]; then
|
||||||
echo 2>&1 "error: you did not choose any of the options"
|
echo 2>&1 "error: you did not choose any of the options"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -145,11 +147,17 @@ list_namespaces() {
|
|||||||
ns_list=$(get_namespaces) || exit_err "error getting namespace list"
|
ns_list=$(get_namespaces) || exit_err "error getting namespace list"
|
||||||
|
|
||||||
for c in $ns_list; do
|
for c in $ns_list; do
|
||||||
if [[ -t 1 && -z "${NO_COLOR:-}" && "${c}" = "${cur}" ]]; then
|
if [[ -n "${_KUBECTX_FORCE_COLOR:-}" || \
|
||||||
|
-t 1 && -z "${NO_COLOR:-}" ]]; then
|
||||||
|
# colored output mode
|
||||||
|
if [[ "${c}" = "${cur}" ]]; then
|
||||||
echo "${cur_ctx_bg}${cur_ctx_fg}${c}${normal}"
|
echo "${cur_ctx_bg}${cur_ctx_fg}${c}${normal}"
|
||||||
else
|
else
|
||||||
echo "${c}"
|
echo "${c}"
|
||||||
fi
|
fi
|
||||||
|
else
|
||||||
|
echo "${c}"
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user