Closed MisterTimn closed 2 years ago
That sounds like a good idea! I've been using p10k but have been thinking of doing it myself.
The command would look like this: kubesess -c context
and kubesess -c namespace
I'll add the same functionality to the default commands as well, might be useful, that would look like: kubesess -c default-context
and kubesess -c default-namespace
Did some preliminary testing, and it looks promising!
Getting current context
Getting current namespace
It's not a lot of time gain but I like my console to be snappy.
There is a release now, both in binary and homebrew with this feature!
Would love it if you would share your prompt script?
prompt_context() {
KUBE_CTX=$(kubesess -c context)
KUBE_NS=$(kubesess -c namespace)
KUBE_PS1="$KUBE_CTX/$KUBE_NS"
if [[ $KUBE_CTX == *"staging"* ]]; then
prompt_segment yellow black "$KUBE_PS1"
elif [[ $KUBE_CTX == *"prod"* ]]; then
prompt_segment red black "$KUBE_PS1"
else
prompt_segment green black "$KUBE_PS1"
fi
}
This is using the agnoster theme with zsh/oh-my-zsh. Mainly wanted it to be very clear wether im deploying to production, staging or dev clusters.
Also I've been hacking together a way to merge all my configs, so far coming up with this (all my base configs have .yaml extension)
KUBECONFIG=$(for YAML in $(find ${HOME}/.kube -name '*.yaml') ; do echo -n ":${YAML}"; done)
kubectl config view --raw > tmp && mv tmp $HOME/.kube/config
chmod o-r $HOME/.kube/config
chmod g-r $HOME/.kube/config
Afterwards I source kubesess and set the config back.
Hmm I've been meaning to support multiple configs actually, created a feature request about it now, do you have any suggestions on how to make it possible? Do you mind if I copy this part to #26
And thanks for the prompt script, will try it out!
Do you mind if I copy this part to #26
Go ahead! fine for me. I'll chime in on the issue
@MisterTimn Played around with your script a bit and thought that I'd share it back! Got rid of kube-ps1 just to simplify my zshrc file tbh and because it was pretty simple to do what it does.
Describe the solution you'd like A flag to output the current context and namespaces OR environment variables that get populated on context change. This can then be used to build a custom prompt.
Describe alternatives you've considered Right now I use
kubectx -c
andkubens -c
to get context and namespace to build my prompt. I use this in favor of other solutions because it is significantly faster.Additional context Since
kubesess
is apparently more efficient than those tools to switch context/namespace, I was wondering if retrieval of current values would perhaps be as fast or even faster.If this is added, then I wouldn't have a need for
kubectx
any longer