mirror of
https://github.com/ahmetb/kubectx.git
synced 2025-07-23 19:35:18 +00:00
Better logic to keep history of context switches
Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
parent
98847e0649
commit
f865312fb5
14
kubectx
14
kubectx
@ -46,15 +46,15 @@ get_contexts() {
|
|||||||
list_contexts() {
|
list_contexts() {
|
||||||
set -u pipefail
|
set -u pipefail
|
||||||
local cur="$(current_context)"
|
local cur="$(current_context)"
|
||||||
local bold=$(tput bold)
|
|
||||||
local yellow=$(tput setaf 3)
|
local yellow=$(tput setaf 3)
|
||||||
|
local darkbg=$(tput setab 0)
|
||||||
local normal=$(tput sgr0)
|
local normal=$(tput sgr0)
|
||||||
|
|
||||||
for c in $(get_contexts); do
|
for c in $(get_contexts); do
|
||||||
if [[ "${c}" = "${cur}" ]]; then
|
if [[ "${c}" = "${cur}" ]]; then
|
||||||
echo "${bold}${yellow}$c${normal}"
|
echo "${darkbg}${yellow}${c}${normal}"
|
||||||
else
|
else
|
||||||
echo "$c"
|
echo "${c}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
@ -66,8 +66,9 @@ read_context() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
save_context() {
|
save_context() {
|
||||||
local prev="$(read_context)"
|
local saved="$(read_context)"
|
||||||
if [[ "${prev}" != "${1}" ]]; then
|
|
||||||
|
if [[ "${saved}" != "${1}" ]]; then
|
||||||
printf %s "${1}" > "${KUBECTX}"
|
printf %s "${1}" > "${KUBECTX}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
@ -81,8 +82,7 @@ set_context() {
|
|||||||
|
|
||||||
switch_context "${1}"
|
switch_context "${1}"
|
||||||
|
|
||||||
# BUG(ahmetb) handle saved == $1, should be noop
|
if [[ "${prev}" != "${1}" ]]; then
|
||||||
if [[ -n "${prev}" ]]; then
|
|
||||||
save_context "${prev}"
|
save_context "${prev}"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user