Code Monkey home page Code Monkey logo

kube-ps1's Introduction

kube-ps1: Kubernetes prompt for bash and zsh

A script that lets you add the current Kubernetes context and namespace configured on kubectl to your Bash/Zsh prompt strings (i.e. the $PS1).

Inspired by several tools used to simplify usage of kubectl.

prompt

prompt_sol_light

prompt_img

prompt demo

Installing

Package managers

MacOS Brew Ports

Homebrew package manager:

brew update
brew install kube-ps1

Arch Linux

AUR Package available at https://aur.archlinux.org/packages/kube-ps1/.

Oh My Zsh

https://github.com/ohmyzsh/ohmyzsh

kube-ps1 is included as a plugin in the oh-my-zsh project. To enable it, edit your ~/.zshrc and add the plugin:

plugins=(
  kube-ps1
)

PROMPT='$(kube_ps1)'$PROMPT # or RPROMPT='$(kube_ps1)'

Zsh Plugin Managers

Using zinit

Update .zshrc with:

zinit light jonmosco/kube-ps1
PROMPT='$(kube_ps1)'$PROMPT # or RPROMPT='$(kube_ps1)'

Fig

Fig adds apps, shortcuts, and autocomplete to your existing terminal.

Install kube-ps1 in zsh, bash, or fish with one click.

From Source

  1. Clone this repository
  2. Source the kube-ps1.sh in your ~/.zshrc or your ~/.bashrc

Zsh

source /path/to/kube-ps1.sh
PROMPT='$(kube_ps1)'$PROMPT # or RPROMPT='$(kube_ps1)'

Bash

source /path/to/kube-ps1.sh
PS1='[\u@\h \W $(kube_ps1)]\$ '

Requirements

The default prompt assumes you have the kubectl command line utility installed. Official installation instructions and binaries are available:

Install and Set up kubectl

If using this with OpenShift, the oc tool needs installed. It can be obtained from brew ports:

brew install openshift-cli

or the source can be downloaded:

OC Client Tools

Set the binary to oc with the following variable:

KUBE_PS1_BINARY=oc

If neither binary is available, the prompt will print the following:

(<symbol>|BINARY-N/A:N/A)

Helper utilities

There are several great tools that make using kubectl very enjoyable:

Tmux port

I have begun porting kube-ps1 to tmux as a status line plugin. If you prefer tmux, and like the functionality provided by kube-ps1, checkout the kube-tmux project

Prompt Structure

The default prompt layout is:

(<symbol>|<context>:<namespace>)

If the current-context is not set, kube-ps1 will return the following:

(<symbol>|N/A:N/A)

Symbols

The default symbols are UTF8 and should work with most fonts. Due to differences in font and terminal spacing, a KUBE_PS1_SYMBOL_PADDING option is available to provide an extra space after the symbol.

In order to have the OpenShift icon, a patched font that contains the glyph must be installed. Nerd Fonts provides an OpenShift icon. Follow the install directions (out of scope for this project) to install a patched font.

Once installed and the font is made active in a terminal session, test to see if the symbol is available:

prompt openshift na

If the symbol is not available, it will display an empty set of brackets or similar:

 echo -n "\ue7b7"

Below is a screenshot of the OpenShift symbol using the Inconsolata font from Nerd Fonts:

prompt openshift

Enabling/Disabling

If you want to stop showing Kubernetes status on your prompt string temporarily run kubeoff. To disable the prompt for all shell sessions, run kubeoff -g. You can enable it again in the current shell by running kubeon, and globally with kubeon -g.

kubeon     : turn on kube-ps1 status for this shell.  Takes precedence over
             global setting for current session
kubeon -g  : turn on kube-ps1 status globally
kubeoff    : turn off kube-ps1 status for this shell. Takes precedence over
             global setting for current session
kubeoff -g : turn off kube-ps1 status globally

Customization

The default settings can be overridden in ~/.bashrc or ~/.zshrc by setting the following variables:

Variable Default Meaning
KUBE_PS1_BINARY kubectl Default Kubernetes binary
KUBE_PS1_NS_ENABLE true Display the namespace. If set to false, this will also disable KUBE_PS1_DIVIDER
KUBE_PS1_PREFIX ( Prompt opening character
KUBE_PS1_SYMBOL_ENABLE true Display the prompt Symbol. If set to false, this will also disable KUBE_PS1_SEPARATOR
KUBE_PS1_SYMBOL_PADDING false Adds a space (padding) after the symbol to prevent clobbering prompt characters
KUBE_PS1_SYMBOL_DEFAULT Default prompt symbol. Unicode \u2388
KUBE_PS1_SYMBOL_USE_IMG false ☸️ , Unicode \u2638 as the prompt symbol
KUBE_PS1_SEPARATOR | Separator between symbol and context name
KUBE_PS1_DIVIDER : Separator between context and namespace
KUBE_PS1_SUFFIX ) Prompt closing character
KUBE_PS1_CLUSTER_FUNCTION No default, must be user supplied Function to customize how cluster is displayed
KUBE_PS1_NAMESPACE_FUNCTION No default, must be user supplied Function to customize how namespace is displayed

For terminals that do not support UTF-8, the symbol will be replaced with the string k8s.

To disable a feature, set it to an empty string:

KUBE_PS1_SEPARATOR=''

Colors

The default colors are set with the following variables:

Variable Default Meaning
KUBE_PS1_PREFIX_COLOR null Set default color of the prompt prefix
KUBE_PS1_SYMBOL_COLOR blue Set default color of the Kubernetes symbol
KUBE_PS1_CTX_COLOR red Set default color of the context
KUBE_PS1_SUFFIX_COLOR null Set default color of the prompt suffix
KUBE_PS1_NS_COLOR cyan Set default color of the namespace
KUBE_PS1_BG_COLOR null Set default color of the prompt background

Blue was used for the default symbol to match the Kubernetes color as closely as possible. Red was chosen as the context name to stand out, and cyan for the namespace.

Set the variable to an empty string if you do not want color for each prompt section:

KUBE_PS1_CTX_COLOR=''

Names are usable for the following colors:

black, red, green, yellow, blue, magenta, cyan

256 colors are available by specifying the numerical value as the variable argument.

Customize display of cluster name and namespace

You can change how the cluster name and namespace are displayed using the KUBE_PS1_CLUSTER_FUNCTION and KUBE_PS1_NAMESPACE_FUNCTION variables respectively.

For the following examples let's assume the following:

cluster name: sandbox.k8s.example.com namespace: alpha

If you're using domain style cluster names, your prompt will get quite long very quickly. Let's say you only want to display the first portion of the cluster name (sandbox), you could do that by adding the following:

function get_cluster_short() {
  echo "$1" | cut -d . -f1
}

KUBE_PS1_CLUSTER_FUNCTION=get_cluster_short

The same pattern can be followed to customize the display of the namespace. Let's say you would prefer the namespace to be displayed in all uppercase (ALPHA), here's one way you could do that:

function get_namespace_upper() {
    echo "$1" | tr '[:lower:]' '[:upper:]'
}

export KUBE_PS1_NAMESPACE_FUNCTION=get_namespace_upper

In both cases, the variable is set to the name of the function, and you must have defined the function in your shell configuration before kube_ps1 is called. The function must accept a single parameter and echo out the final value.

Bug Reports and shell configuration

Due to the vast ways of customizing the shell, please try the prompt with a minimal configuration before submitting a bug report.

This can be done as follows for each shell before loading kube-ps1:

Bash:

bash --norc

Zsh:

zsh -f
or
zsh --no-rcs

For the OpenShift symbol, a patched font that contains the icon must be installed. Nerd Fonts Downloads provides patched fonts containing the symbol. Please consult their documentation for this, support is out of scope for this project.

Contributors

kube-ps1's People

Contributors

adamcstephens avatar ahmetb avatar artmorse avatar astraw99 avatar bradym avatar chriskepticode avatar drubin avatar hyperupcall avatar ibayramli avatar jamesmcdonald avatar jonathanmdr avatar jonmosco avatar luisdavim avatar pabrahamsson avatar pansachin avatar reneluria avatar rootsongjc avatar sistason avatar zyf0330 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

kube-ps1's Issues

Trim cluster name & namespace name

For long cluster names & namespaces it takes a lot of space in a prompt:
(kubernetes.us-west-2.dev.subenv.company.domain:application.namepsace)~prompt$

Two options can be introduced:

  • namespace trim len
  • cluster trim len

setting both to 10 will end to:
(kube.us-we..:applicatio..)~prompt$
default: -1 (no trim)

KUBE_PS1_SEPARATOR not working

(⎈ |test:default) ➜  ~ export KUBE_PS1_PREFIX=''
⎈ |test:default) ➜  ~ export KUBE_PS1_SEPARATOR=''
⎈ |test:default) ➜  ~ export KUBE_PS1_SEPARATOR='x'
⎈ |test:default) ➜  ~

Add LICENSE

I see it's on the file, but would be nice to have in repo root as a file as well. GitHub detects that and shows in the UI.

Display kube-ps1 prompt on the right side of the terminal

Could you possibly add the ability to display the kube_ps1 part of the prompt on the right side of the terminal (refer to screenshots).

This is how kube-ps1 looks in my terminal window:
screen shot 2018-08-14 at 17 49 11

And this is how zsh-kubectl-prompt looks in my terminal window:
screen shot 2018-08-14 at 17 49 50

I think a custom option that would implement this functionality would also be extremely useful for people who use bullet train/powerline9k type themes where the prompt tends to get pretty long.

If there is already a way through which I can accomplish this by modifying my zsh config then do let me know, I'd highly appreciate that and would love to switch to over to kube-ps1.

Add support for aliases

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.

Whitespace is appended on tab completion

Hey,
thanks for this nice tool. I have just one problem: Everytime i hit tab to complete paths in zsh, it appends a whitespace and thus destroys further navigation with tab.
Any idea?
Here is my config (.zshrc):

source /usr/local/Cellar/kube-ps1/0.6.0/share/kube-ps1.sh
KUBE_PS1_SYMBOL_USE_IMG=true
KUBE_PS1_SYMBOL_ENABLE=true
KUBE_PS1_NS_ENABLE=true
PROMPT=$(kube_ps1)$PROMPT
KUBE_PS1_BG_COLOR=black

Faster ways to calculate context/namespace

As seen in #4, kube_ps1 shell function is slow (adds about 200 ms to every shell prompt users get).
This is because kubectl is not a fast program as one would think and it has a startup latency.

I have a few ideas to make this faster. Here's my top idea that I think can work really fast:

  • make yq (https://github.com/kislyuk/yq) (or another yaml parser) a mandatory dependency for this script
  • figure out where the kubectl config file is ($KUBECONFIG if set, otherwise ~/.kube/config)
  • read the namespace/context with a cat $f | yq (..path-query..).

this should be muuuchhhh faster, I bet it can complete within 10 ms, which is an acceptable delay.

Prompt is slow when enabled

First off, awesome prompt! I enabled it and noticed that it appears to significantly slow down my prompt. The simple test is hitting enter a few times. If I run kubeoff the response is immediate, but if I run kubeon then hitting enter multiple times results in a rather significant delay. Unfortunately, I have not had much time to look into why this might be the case, but figured I would file an issue.

Could not customize KUBE_PS1_SYMBOL_DEFAULT on bash

Hello, I'm using a font that didn't support the unicode symbol \u2388, so I try to customize the symbol in ~/.bashrc, then I found the symbol is hard coded in the bash block of _kube_ps1_symbol(), not using the KUBE_PS1_SYMBOL_DEFAULT.
I think this is the reason why the customization of the symbol not taking effect, tried to fix it and tested on bash 4.x.
Due to the different encode way , I don't know how to fix it on bash version lower than 4.x, because I don't have the envirment to test it, does anyone have a good idea?

stat: cannot read file system information for '%m': No such file or directory

seeing the following in osx with debug on, the prompt never displays any information.

[⎈ |:]]

+++ stat -f %m /Users/user/.kube/config
stat: cannot read file system information for '%m': No such file or directory
++ mtime='  File: "/Users/user/.kube/config"
    ID: 100000500000018 Namelen: ?       Type: apfs
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 488475719  Free: 420205592  Available: 418951658
Inodes: Total: 9223372036854775807 Free: 9223372036852263089'
++ [[   File: "/Users/user/.kube/config"
    ID: 100000500000018 Namelen: ?       Type: apfs
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 488475719  Free: 420205592  Available: 418951658
Inodes: Total: 9223372036854775807 Free: 9223372036852263089 -gt 0 ]]
-bash: [[: File: "/Users/user/.kube/config"
    ID: 100000500000018 Namelen: ?       Type: apfs
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 488475719  Free: 420205592  Available: 418951658
Inodes: Total: 9223372036854775807 Free: 9223372036852263089: syntax error in expression (error token is ": "/Users/user/.kube/config"
    ID: 100000500000018 Namelen: ?       Type: apfs
Block size: 4096       Fundamental block size: 4096
Blocks: Total: 488475719  Free: 420205592  Available: 418951658
Inodes: Total: 9223372036854775807 Free: 9223372036852263089")

Proposal: kubeon/kubeoff

I propose we introduce these commands kubeon/kubeoff to indicate whether we want Kubernetes status shown on our ps1 or not.

  • kubeoff would create a sentinel file, say, ~/.kube/ps1/off. When this exists, the kube_ps1 would return empty string/noop, so no Kubernetes shown in PS1.
  • kubeon would delete that file.

Kubernetes context not loaded on shell creation

Hello,

I've sourced the kube-ps1.sh file in my bash configuration and modified my bash prompt to include the kubernetes context information.
However, it seems that when I open a new shell for the first time, the kubernetes context is not loaded. Only after hitting 'Enter' on the command line, is the context loaded.
See my prompt output below.

Last login: Sun Jan 21 19:25:42 on ttys002
(⎈ |:) » ~
(⎈ |docker-for-desktop:default) » ~

Any idea what could be wrong in my configuration ?

Thanks.

retake demo.gif

It looks like it's outdated.

It can now use kubeon/kubeoff, along with the usual kubectx/kubens jazz!

Fails if there's no config in ~/.kube

I have 3 different contexts, all set in KUBECONFIG.
kube-prompt fails when I try to get a certain pod or service

>>> get pods panic: stat /Users/tarekmehrez/.kube/config: no such file or directory

goroutine 36 [running]:
github.com/c-bata/kube-prompt/kube.NewClient(0x0)
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/kube/client.go:29 +0x140
github.com/c-bata/kube-prompt/kube.getClient(0x0)
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/kube/client.go:14 +0x2e
github.com/c-bata/kube-prompt/kube.fetchPods()
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/kube/resource.go:177 +0x72
created by github.com/c-bata/kube-prompt/kube.getPodSuggestions
	/Users/a14737/go/src/github.com/c-bata/kube-prompt/kube/resource.go:183 +0x39

Is there a way that this might work just by checking my current context?

Why is kubeon/kubeoff deprecated now?

kubeon/kubeoff no longer seems to work with comments indicating deprecation in the source code.

Was there a discussion about this? I’m lately a little frustrated in number of the ways the project is getting in my way of doing things.

I have developed kubectx/kubens so people set it up once and forget about it. So far I tend to think I achieved that. I have ideas to add there but I’ve been holding off on making major changes, because a lot of people tell me that it’s very much central to their day-to-day workflow.

I want to see the same from kube-ps1. However, so far my experience is reflecting it's been the case that things keep breaking, too many configurable knobs mostly untested, kubeon/kubeoff stops working either because of badly implemented state machine or some arbitrary deprecation.

I am no longer able to keep up with these changes. If you are seeking help or guidance on this project, I can provide support such as reviewing every single commit. But I can no longer stand the fact that this project is being pulled to different directions in many directions. I just want it to work.

Does not work when bash-git-prompt is already installed.

Installed bash-git-prompt using brew before on my MacOS.

Here is how my ~/.bash_profile look like:

if [ -f $(brew --prefix)/etc/bash_completion ]; then
    source $(brew --prefix)/etc/bash_completion
fi

if [ -f $(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh ]; then
    __GIT_PROMPT_DIR=$(brew --prefix)/opt/bash-git-prompt/share
    source $(brew --prefix)/opt/bash-git-prompt/share/gitprompt.sh
fi

if [ -f $(brew --prefix)/opt/kube-ps1/share/kube-ps1.sh ]; then
    source $(brew --prefix)/opt/kube-ps1/share/kube-ps1.sh
    PS1='$(kube_ps1) $(__git_ps1)'
fi

However the new terminal window only shows git prompt.

I also tried putting the new lines in ~/.bashrc as said in the installation setup, but no luck.

I also tried putting the new lines before git-prompt setup, but no luck.

The only way to get kube_ps1 to work is to remove git-prompt.

Proposal: kubeon/kubeoff should only affect current session

Kubeon/off currently applies to all shells based off a file check.

I think these functions could be more useful if they apply to the current session only. This can be achieved by setting and unsetting a variable:

KUBE_PS1_DISABLE=true
unset KUBE_PS1_DISABLE
then test for this on kube_ps1

For zsh prompt config error

As the README, config ~/.zshrc

source /path/to/kube-ps1.sh
PROMPT='$(kube_ps1) $PROMPT'

Get this prompt:

(⎈ |kubernetes:default)$(kube_ps1) $PROMPT

Change to

PROMPT='$(kube_ps1)'$PROMPT

Get this:

(⎈ |kubernetes:dev)➜  ~

Enabling kube-ps1 messes up completion in zsh?

It looks like my zsh completion doesn't work as expected when the kube-ps1 prompt is enabled. This is the relavant parts of my ~/.zshrc file:

KUBE_PS1_SYMBOL_USE_IMG=true
KUBE_PS1_SYMBOL_ENABLE=true
KUBE_PS1_SEPARATOR=' '
KUBE_PS1_PREFIX=''
KUBE_PS1_SUFFIX=''
KUBE_PS1_NS_ENABLE=false
source ~/.zsh/scripts/kube-ps1.sh
PROMPT='$(kube_ps1)'$PROMPT
# Disable kube prompt by default, enable with "kubeon"
kubeoff

The prompt now looks like this when I start a new window:
image

If I enter kubec and press tab it's expanded to:
image

But when I run kubeon and enter kubec and pressing tab I get this:
image

Notice the extra "k" that is inserted.

Do not load zsh modules

kube-ps1/kube-ps1.sh

Lines 61 to 62 in 7d06e2d

zmodload zsh/stat
zmodload zsh/datetime

This caused me at least 1 hour of debugging.

I was trying to figure out what the hell is loading zsh stat module, because it prevented me from calling the actual stat binary on my machine.

Please remove these lines. It's unexpected for a simple tool like kube-ps1 to have substantial side-effects like this.

Specifying different color for bash prompt

Hello,

I'm trying to specify a different color for the Kubernetes context according to the documentation for bash but this doesn't seem to work.
Would you be able to assist me with this ?
I basically want to modify the context color from red to purple.

Thanks.

Regards,
Dieter.

on/off -g does not change the current session

Starting state: kubeoff -g, run 3 shell windows

When I run kubeon -g on the current shell, I expect:

  • current shell will turn on the PS1
  • new shells will also have PS1 turned on
  • already open shells (other tabs) will not change behavior when I hit return

Current behavior:

  • current shell doesn't turn on PS1 (UNEXPECTED)
  • new shells have PS1 turned on
  • already open shells (other tabs) are turning it on (UNEXPECTED)

Starting state: kubeon -g, run 3 shell windows

When I run kubeoff -g on the current shell, I expect:

  • current shell will turn OFF the PS1
  • new shells will also have PS1 turned OFF
  • already open shells (other tabs) will not change behavior when I hit return

Current behavior:

  • current shell doesn't turn off PS1 (UNEXPECTED)
  • new shells have PS1 turned off
  • already open shells (other tabs) are turning it on (UNEXPECTED)

Are my expectations not accurate? I kind of expected kubeon/kubeoff to work this way.

bash error

In bash following lines are not working. Removing parts in brackets is work arounding it.

https://github.com/jonmosco/kube-ps1/blob/master/kube-ps1.sh#L31-L34

github.com/jonmosco/kube-ps1/kube-ps1.sh: line 31: conditional binary operator expected
github.com/jonmosco/kube-ps1/kube-ps1.sh: line 31: syntax error near KUBE_PS1_PREFIX' github.com/jonmosco/kube-ps1/kube-ps1.sh: line 31: [[ -v KUBE_PS1_PREFIX ]] || KUBE_PS1_PREFIX="("'

Add ability to specify background color

I'd like to change the background color of prompt so it would be nice if this would be available as a configuration option. Currently I do like this to get it to work the way I want:

PROMPT=%{$bg[white]%}'$(kube_ps1)'$PROMPT

Do not update ps1 cache if kube config's file type is symlink

stat function does not check target file's changed time but symlink files' changed time. Therefore, _kube_ps1_file_newer_than function always return false if kube config file is symlink

_kube_ps1_file_newer_than() {
  local mtime
  local file=$1
  local check_time=$2

  if [[ "${KUBE_PS1_SHELL}" == "zsh" ]]; then
    mtime=$(stat +mtime "${file}")
  elif stat -c "%s" /dev/null &> /dev/null; then
    # GNU stat
    mtime=$(stat -c %Y "${file}")
  else
    # BSD stat
    mtime=$(stat -f %m "$file")
  fi

  [[ "${mtime}" -gt "${check_time}" ]]
}

seeing empty namespace

kubectl config view --minify --output 'jsonpath={..namespace}' can return empty if you haven't explicitly set the namespace.

I'm seeing (⎈ |minikube:) in my prompt, for instance. Setting a namespace fixes it. So maybe default to "default" if value is missing.

(⎈ |minikube:) ➜  ~ git:(master) kubens default
Context "minikube" modified.
Active namespace is "default".
(⎈ |minikube:default) ➜  ~ git:(master)

wrong unicode symbols

I see similar issue was reported but closed here.
In my case (Linux Mint 18.3 Sylvia) it looks like this:

image

I fixed it by using:
_KUBE_PS1_OPEN_ESC=$'' _KUBE_PS1_CLOSE_ESC=$''
instead of:
_KUBE_PS1_OPEN_ESC=$'\001' _KUBE_PS1_CLOSE_ESC=$'\002'

kubeon/kubeoff not working as expected

  1. open terminal tab → kube-ps1 string shows (expected)
  2. kubeoff -g→ hides kube-ps1 string (expected)
  3. kubeon → ps1 string still does not show up (NOT EXPECTED)

Ability to hide namespace

Would it be possible and make sense to add an environment variable that hides the namespace? In my case I virtually never change the namespace so I might as well not show it.

KUBECONFIG ENV ignored

When using the KUBECONFIG environment variable to change the path to the kubeconfig file it results in the prompt not being updated.

~  (⎈ |minikube:default) export  KUBECONFIG=~/.kube/config-n10
~  (⎈ |minikube:default) kctx
kubernetes-admin@kubernetes

I would have expected my prompt to have changed to

~  (⎈ |kubernetes-admin@kubernetes:default)

command not found: add-zsh-hook

I just downloaded from master and sourced, but I got:

_kube_ps1_shell_settings:4: command not found: add-zsh-hook

I'm using oh-my-zsh on Mac.

side-effect/overriden environment variables

the following doesn't work for two reasons:

# .zshrc file:
export KUBE_PS1_PREFIX='['
export KUBE_PS1_SUFFIX=']'
source "$HOME/workspace/dotfiles/kube-ps1.sh"
  1. it ignores my settings
  2. replaces the passed value with the defaults ( and ).
(⎈ |docker-for-desktop:default) ➜  ~ env | grep KUBE
KUBE_PS1_PREFIX=(
KUBE_PS1_SUFFIX=)

ideally the order of export and source shouldn't matter in this case I think.

If I move export after sourcing, it works.

kube-ps1 messed up my kubectl bash completion

Hi!

I've installed kube-ps1 but it messed my bash completion :(
It completes commands properly but not resources names (for instance pod names).

It still won't work, even after I've uninstalled kube-ps1.

Some help would be really appreciated, thanks!

Rendering Issue

Ubuntu: 16.04
Issue
The latest pull has changed the icon to odd characters.
Example:
[(�⎈ |minikube:default)�]

empty KUBE_PS1_SEPARATOR not working

export KUBE_PS1_SEPARATOR=''

when I specify that I still get the | character:

{⎈ |test:default}

any other non-empty value works fine, however.

command not found: add-zsh-hook

Hi, there, after I ran upgrade_oh_my_zsh and restarted shell, I get this:

.oh-my-zsh/plugins/kube-ps1/kube-ps1.plugin.zsh:24: command not found: add-zsh-hook

Best regards

kube_ps1 adds 200+ ms to every command

not particularly an issue, but I think calling kube_ps1 function takes about 200ms. this is because kube-ps1 calls kubectl, twice, for each shell prompt.

this is visibly making my shell slower.

  • just keep typing ls(enter), ls(enter), ls(enter) ,ls(enter) and get a feeling for it
  • reset the function: function kube_ps1() {}
  • now run ls(enter), ls(enter), ls(enter) ,ls(enter)
  • much faster without kube_ps1

to measure the delay added, paste this to your shell:

while :; do
    ts=$(date +%s%N) ; kube_ps1 ; tt=$((($(date +%s%N) - $ts)/1000000)) ; echo "Time taken: $tt milliseconds"
done
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 229 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 201 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 238 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 219 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 204 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 210 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 207 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 203 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 208 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 209 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 198 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 208 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 219 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 242 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 218 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 208 milliseconds
(%f%F{blue}⎈ %f|%F{red}minikube%f:%F{cyan}default%f)
Time taken: 220 milliseconds

I'll talk about some potential improvements in the next isssue.

Compatibility with oh-my-zsh

Is this working with oh-my-zsh?

I am on a CentOS 7 machine and I have kubectl installed. I am using oh-my-zsh with agnoster as a theme.

I have added the following lines in my .zshrc file but nothing is happening when I source /.zshrc`:

source /path/to/kube-ps1.sh
PROMPT='$(kube-ps1)'$PROMPT

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.