• Stars
    star
    557
  • Rank 79,968 (Top 2 %)
  • Language
    Shell
  • License
    MIT License
  • Created over 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Display information about the kubectl current context and namespace in zsh prompt.

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.

More Repositories

1

capturejs

Full webpage capture command-line tool with PhantomJS and NodeJS
JavaScript
272
star
2

opener

Open URL in your local web browser from the SSH-connected remote environment.
Go
141
star
3

kubectl-open-svc-plugin

kubectl open-svc plugin makes services accessible via their ClusterIP from outside your cluster
Go
119
star
4

kubectl-view-serviceaccount-kubeconfig-plugin

A kubectl plugin that show a kubeconfig to access the apiserver with a specified serviceaccount.
Go
110
star
5

ksort

Sort manfest files in a proper order by Kind
Go
59
star
6

close-pull-request

A GitHub Action to automatically close pull requests.
JavaScript
45
star
7

minikube-ingress-dns

Configure and restart dnsmasq automatically for k8s Ingress LB on minikube.
Shell
35
star
8

vim-quickrun-markdown-gfm

vim-quickrun plugin for Markdown by GitHub Markdown API
CSS
29
star
9

electron-boilerplate

A electron app template with React, babel, sass, gulp and bower 🎉
JavaScript
13
star
10

dotfiles

my config files
Vim Script
8
star
11

gyazo-dropbox

yet another Gyazo Server with Dropbox
Ruby
7
star
12

ga

The GitHub Actions helper command-line tool
TypeScript
7
star
13

node-imageviewurlreplace

JavaScript
5
star
14

vim-vimperator

VIMperator configuration file
Vim Script
5
star
15

ansible-bootstrap-devenv

Ansible playbooks for bootstrapping development environment
Shell
5
star
16

prometheus-up-and-running-ja-examples

『入門 Prometheus』9章 コンテナとKubernetes サンプルファイル Kubernetes 1.13 対応版
HCL
5
star
17

devbox

A Docker image for my development environment
Shell
4
star
18

debug

My debugging container image
Dockerfile
4
star
19

kojin-no-kenkai-jp

個人の見解.jp
JavaScript
4
star
20

httpdebugger

This is an http.RoundTripper that will display information about the requests passing through it based on what is configured.
Go
4
star
21

marklite

JavaScript
3
star
22

kubectl-expla.in

Awesome kubectl explain 🎉
JavaScript
2
star
23

text.superbrothers.dev

HTML
2
star
24

brewfile

Ruby
2
star
25

feedmaker

JavaScript
1
star
26

superbrothers.github.com

1
star
27

homebrew-whalebrew

Ruby
1
star
28

kind-wrapper

Shell
1
star
29

kubectl-plugins

My kubectl plugin scripts.
Shell
1
star
30

paperclip-sample-app

rails3.1 paperclip2.4.1
Ruby
1
star
31

setup-ga

This action sets up ga which is the GitHub Actions helper command-line tool.
TypeScript
1
star
32

anime-blu-ray-box-feed

JavaScript
1
star