mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-08-13 13:06:14 +00:00
Configure highlight color for current context & namespace using environment variable
This commit is contained in:
parent
c23c2a9e29
commit
9beb1a1587
15
README.md
15
README.md
@ -73,6 +73,21 @@ Active namespace is "default".
|
|||||||
|
|
||||||
-----
|
-----
|
||||||
|
|
||||||
|
### Highlight Current Context
|
||||||
|
By default, current context is highlighted by yellow foreground & black background
|
||||||
|
|
||||||
|
It is configurable by setting environment variables `KUBECTX_CURRENT_FGCOLOR` & `KUBECTX_CURRENT_BGCOLOR`
|
||||||
|
|
||||||
|
To change foreground colour to Blue for highlighting current context:
|
||||||
|
|
||||||
|
`export KUBECTX_CURRENT_FGCOLOR=$(tput setaf 6)`
|
||||||
|
|
||||||
|
To change background colour to White for highlighting current context:
|
||||||
|
|
||||||
|
`export KUBECTX_CURRENT_FGCOLOR=$(tput setaf 7)`
|
||||||
|
|
||||||
|
Refer color codes [here](https://linux.101hacks.com/ps1-examples/prompt-color-using-tput/)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
### macOS
|
### macOS
|
||||||
|
6
kubectx
6
kubectx
@ -58,9 +58,13 @@ list_contexts() {
|
|||||||
darkbg=$(tput setab 0)
|
darkbg=$(tput setab 0)
|
||||||
normal=$(tput sgr0)
|
normal=$(tput sgr0)
|
||||||
|
|
||||||
|
local cur_ctx_fg cur_ctx_bg
|
||||||
|
cur_ctx_fg=${KUBECTX_CURRENT_FGCOLOR:-$yellow}
|
||||||
|
cur_ctx_bg=${KUBECTX_CURRENT_BGCOLOR:-$darkbg}
|
||||||
|
|
||||||
for c in $(get_contexts); do
|
for c in $(get_contexts); do
|
||||||
if [[ -t 1 && "${c}" = "${cur}" ]]; then
|
if [[ -t 1 && "${c}" = "${cur}" ]]; then
|
||||||
echo "${darkbg}${yellow}${c}${normal}"
|
echo "${cur_ctx_bg}${cur_ctx_fg}${c}${normal}"
|
||||||
else
|
else
|
||||||
echo "${c}"
|
echo "${c}"
|
||||||
fi
|
fi
|
||||||
|
6
kubens
6
kubens
@ -109,12 +109,16 @@ list_namespaces() {
|
|||||||
darkbg=$(tput setab 0)
|
darkbg=$(tput setab 0)
|
||||||
normal=$(tput sgr0)
|
normal=$(tput sgr0)
|
||||||
|
|
||||||
|
local cur_ctx_fg cur_ctx_bg
|
||||||
|
cur_ctx_fg=${KUBECTX_CURRENT_FGCOLOR:-$yellow}
|
||||||
|
cur_ctx_bg=${KUBECTX_CURRENT_BGCOLOR:-$darkbg}
|
||||||
|
|
||||||
local cur ns_list
|
local cur ns_list
|
||||||
cur="$(current_namespace)"
|
cur="$(current_namespace)"
|
||||||
ns_list=$(get_namespaces)
|
ns_list=$(get_namespaces)
|
||||||
for c in $ns_list; do
|
for c in $ns_list; do
|
||||||
if [[ -t 1 && "${c}" = "${cur}" ]]; then
|
if [[ -t 1 && "${c}" = "${cur}" ]]; then
|
||||||
echo "${darkbg}${yellow}${c}${normal}"
|
echo "${cur_ctx_bg}${cur_ctx_fg}${c}${normal}"
|
||||||
else
|
else
|
||||||
echo "${c}"
|
echo "${c}"
|
||||||
fi
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user