Better logic to keep history of context switches

Signed-off-by: Ahmet Alp Balkan <ahmetb@google.com>
This commit is contained in:
Ahmet Alp Balkan 2017-03-28 21:58:07 -07:00
parent 98847e0649
commit f865312fb5
No known key found for this signature in database
GPG Key ID: 5C02521D7B216AD6

14
kubectx
View File

@ -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
} }