Zsh Kubectl Prompt

Display information about the kubectl current context and namespace in zsh prompt.
Alternatives To Zsh Kubectl Prompt
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Kubectx14,910
7 days ago26January 11, 202246apache-2.0Go
Faster way to switch between clusters and namespaces in kubectl
Kube Ps12,971
3 months ago1March 03, 20218apache-2.0Shell
Kubernetes prompt info for bash and zsh
Gbt474
2 years ago1June 18, 2021mitGo
Highly configurable prompt builder for Bash, ZSH and PowerShell written in Go.
Zsh Kubectl Prompt375
2 years agomitShell
Display information about the kubectl current context and namespace in zsh prompt.
Fzf Zsh Completions101
21 days ago1mitShell
Fuzzy completions for fzf and Zsh (git, kubectl, docker, ...)
Kube Aliases82
a month ago9mitShell
Kubernetes Aliases and Bash Functions
Zsh Kubectl Completion30
2 years agogpl-3.0Makefile
Rich zsh completion for the kubectl command.
Awesome Bash Alias24
3 years ago6
A curated list of awesome Bash aliases.
Dops22
4 years agoShell
Docker, Docker Machine, Docker Compose, Terraform, Packer, Ansible and kubectl in Docker
Plugin Kubectl18
22 days agomitShell
Kubectl plugin for Oh My Fish (similar to oh-my-zsh kubectl)
Alternatives To Zsh Kubectl Prompt
Select To Compare


Alternative Project Comparisons
Readme

zsh-kubectl-prompt

This script displays information about the kubectl current context and namespace in zsh prompt.

Screenshot

Usage

Clone this repository and source the kubectl.zsh from your ~/.zshrc config file, and configure your prompt.

autoload -U colors; colors
source /path/to/zsh-kubectl-prompt/kubectl.zsh
RPROMPT='%{$fg[blue]%}($ZSH_KUBECTL_PROMPT)%{$reset_color%}'

Or create different style depending on user, context, namespace. The plugin creates 4 variables:

  • ZSH_KUBECTL_CONTEXT
  • ZSH_KUBECTL_NAMESPACE
  • ZSH_KUBECTL_PROMPT
  • ZSH_KUBECTL_USER

For example, make the prompt red when the username matches admin.

autoload -U colors; colors
source /path/to/zsh-kubectl-prompt/kubectl.zsh
function right_prompt() {
  local color="blue"

  if [[ "$ZSH_KUBECTL_USER" =~ "admin" ]]; then
    color=red
  fi

  echo "%{$fg[$color]%}($ZSH_KUBECTL_PROMPT)%{$reset_color%}"
}
RPROMPT='$(right_prompt)'

Also you can install with homebrew.

$ brew tap superbrothers/zsh-kubectl-prompt
$ brew install zsh-kubectl-prompt

Customization

Change the separator between context and namespace:

zstyle ':zsh-kubectl-prompt:' separator '|'

Add custom character before the prompt:

zstyle ':zsh-kubectl-prompt:' preprompt '<'

Add custom character after the prompt:

zstyle ':zsh-kubectl-prompt:' postprompt '>'

Does not display the current namespace:

zstyle ':zsh-kubectl-prompt:' namespace false

Use another binary instead of kubectl to get the information (e.g. oc):

zstyle ':zsh-kubectl-prompt:' binary 'oc'

With a plugin manager

If you use zgen, load this repository as follows:

source "${HOME}/.zgen/zgen.zsh"

# if the init script doesn't exist
if ! zgen saved; then
    # specify plugins here
    zgen load superbrothers/zsh-kubectl-prompt

    # generate the init script from plugins above
    zgen save
fi

autoload -U colors; colors
RPROMPT='%{$fg[blue]%}($ZSH_KUBECTL_PROMPT)%{$reset_color%}'

If you use antigen, load this repository as follows:

source /path-to-antigen/antigen.zsh

# load this plugin
antigen bundle superbrothers/zsh-kubectl-prompt

# tell antigen that you're done.
antigen apply

autoload -U colors; colors
RPROMPT='%{$fg[blue]%}($ZSH_KUBECTL_PROMPT)%{$reset_color%}'

If you use oh-my-zsh, load this repository as follows:

  1. Clone the repo into oh-my-zsh custom plugins folder
git clone https://github.com/superbrothers/zsh-kubectl-prompt.git ${ZSH_CUSTOM:-~/.oh-my-zsh/custom}/plugins/zsh-kubectl-prompt
  1. Activate the plugin your .zshrc by appending it to the plugin section
plugins=( [plugins...] zsh-kubectl-prompt)
  1. Configure your prompt (or check how to customize the theme plugin you are using)
RPROMPT='%{$fg[blue]%}($ZSH_KUBECTL_PROMPT)%{$reset_color%}'

Note: Remember to source the .zshrc or restart your shell after step 2

License

This script is released under the MIT License.

Popular Zsh Projects
Popular Kubectl Projects
Popular Command Line Interface Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Shell
Plugin
Kubernetes
Zsh
Kubectl