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

One improvement to kube_ctx_namespace #96

Open
ildar-shaimordanov opened this issue Aug 30, 2023 · 0 comments
Open

One improvement to kube_ctx_namespace #96

ildar-shaimordanov opened this issue Aug 30, 2023 · 0 comments

Comments

@ildar-shaimordanov
Copy link

ildar-shaimordanov commented Aug 30, 2023

Hi all!

Looking for new ideas I found your project. It gave me some ones and I'd like to share my visions with you. Hope it will help you further.

fubectl/fubectl.source

Lines 80 to 85 in 3950b1e

# [kube_ctx_namespace] get current namespace
function kube_ctx_namespace() {
local default_ns="$(kubectl config view --minify|grep namespace: |sed 's/namespace: //g'|tr -d ' ')"
default_ns="${default_ns:-default}"
echo "$default_ns"
}

I think the snippet above can be improved a little bit in the way as below. It requires kubectl itself and its jsonpath features that have already been embedded.

kubectl config view --minify \
-o jsonpath="{range .contexts[*].context}{@.user}{\"@\"}{@.cluster}{\":\"}{@.namespace}{\"\n\"}"

It displays the current context in the form similar to the unix prompt like user@cluster:namespace. It's constructed to be used directly or as an alias. You can take it as is or modify on your wants or drop as a bad idea for your project :).

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

1 participant