Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for aliases #24

Closed
johanhaleby opened this issue Jan 19, 2018 · 3 comments
Closed

Add support for aliases #24

johanhaleby opened this issue Jan 19, 2018 · 3 comments

Comments

@johanhaleby
Copy link

johanhaleby commented Jan 19, 2018

When using kube-ps1 the prompt can be very long as seen in this example:

image

It would be great if one could create a shorter alias for the context (and possibly namespace as well).

For example:

KUBE_PS1_CONTEXT_ALIASES='gke_xxxxxxxxxxxxxxxxxxxxxxx_europe-west1-c_prod=prod, another_context=another'

thus rendering only prod instead of gke_xxxxxxxxxxxxxxxxxxxxxxx_europe-west1-c_prod and another instead of another_context as context name in the prompt.

@jonmosco
Copy link
Owner

jonmosco commented Jan 19, 2018

This feature is available in kubectl with kubectl config rename-context:
kubernetes/kubernetes#45131

Thanks for this suggestion, but I think the contexts should stay in the kubeconfig files so the logic for updating the prompt can stay intact.

You could remap your aliases if you want with an array possibly, then just add it to your prompt with something like this:

my_kube_ps1_alias() {
case $1 in
super-long-name) echo short;;
*) echo $1;;
esac
}

PS1='\u @ \h $(my_kube_ps1_alias $KUBE_PS1_CONTEXT) $>'

@johanhaleby
Copy link
Author

Thanks, rename-context is probably good enough for me now (didn't know about it!)

@jonmosco
Copy link
Owner

No problem, thanks for using the prompt!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants