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

Automatically disable kube-ps1 when no context is available #179

Open
dashie opened this issue Jul 27, 2023 · 3 comments
Open

Automatically disable kube-ps1 when no context is available #179

dashie opened this issue Jul 27, 2023 · 3 comments

Comments

@dashie
Copy link

dashie commented Jul 27, 2023

Is it possibile to automatically disable kube-ps1 when no context is set?
So have a empty string instead of (<symbol>|N/A:N/A)

@credativ-dar
Copy link

Just in case you missed that: kubeoff -g turns it off by default so you can just kubeon if you need it, I guess that's easier for most people than unsetting the context.

@jonmosco
Copy link
Owner

Yes, that is the solution for this is using the kubeon and kubeoff functions: https://github.com/jonmosco/kube-ps1?tab=readme-ov-file#enablingdisabling

@gitmpr
Copy link

gitmpr commented Mar 8, 2025

kubeon and kubeoff only remove the kube-ps1 part from the PS1 string for the current shell. This is not exactly the requested feature here.

What we want instead is to conditionally remove the kube-ps1 part from the PS1 if no context is set. This can be achieved easily by adding an extra check and return early if no context is set

[[ "${KUBE_PS1_CONTEXT}" == "N/A" ]] && return

at the start of the kube_ps1() function

@jonmosco
If you can acknowledge this I can make a PR and also make it configurable with a KUBE_PS1_HIDE_IF_NOCONTEXT environment variable setting, set to false by default

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

4 participants