Skip to content

Instantly share code, notes, and snippets.

@bageljp
Created January 4, 2019 12:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bageljp/02149dd2c8e3298b6c8f52f3697b91fe to your computer and use it in GitHub Desktop.
Save bageljp/02149dd2c8e3298b6c8f52f3697b91fe to your computer and use it in GitHub Desktop.
fish_prompt with k8s ctx and ns
$ diff ~/.config/fisherman/bobthefish/fish_prompt.fish ~/.config/fisherman/bobthefish/fish_prompt.fish.org Fri Jan 4 21:11:16 2019
509,516c509
< # Customize: START
< set -l ctx (string trim -c '"\' ' -- $val)
< set -l ns (kubectl config view -o "jsonpath={.contexts[?(@.name==\"$ctx\")].context.namespace}")
< [ -z $ns ]; and set -l ns 'default'
< set -l context "$ctx/$ns"
< # Customize: END
<
< #set -l context (string trim -c '"\' ' -- $val)
---
> set -l context (string trim -c '"\' ' -- $val)
$ diff ~/.config/fisherman/bobthefish/fish_right_prompt.fish ~/.config/fisherman/bobthefish/fish_right_prompt.fish.org Fri Jan 4 21:09:32 2019
59,83d58
< # Customize: START
< # refs: https://github.com/Ladicle/fish-kubectl-prompt
< function __kubectl_status
< [ -z "$KUBECTL_PROMPT_ICON" ]; and set -l KUBECTL_PROMPT_ICON "⎈"
< [ -z "$KUBECTL_PROMPT_SEPARATOR" ]; and set -l KUBECTL_PROMPT_SEPARATOR "/"
< set -l config $KUBECONFIG
< [ -z "$config" ]; and set -l config "$HOME/.kube/config"
< if [ ! -f $config ]
< echo (set_color red)$KUBECTL_PROMPT_ICON" "(set_color white)"no config"
< return
< end
<
< set -l ctx (kubectl config current-context 2>/dev/null)
< if [ $status -ne 0 ]
< echo (set_color red)$KUBECTL_PROMPT_ICON" "(set_color white)"no context"
< return
< end
<
< set -l ns (kubectl config view -o "jsonpath={.contexts[?(@.name==\"$context\")].context.namespace}")
< [ -z $ns ]; and set -l ns 'default'
<
< echo (set_color cyan)$KUBECTL_PROMPT_ICON" "(set_color white)"($ctx$KUBECTL_PROMPT_SEPARATOR$ns)"
< end
< # Customize: END
<
90d64
< #__kubectl_status
@bageljp
Copy link
Author

bageljp commented Jan 4, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment