chore(kube-ps1): update to 0b0e6daf (#13503)

Co-authored-by: ohmyzsh[bot] <54982679+ohmyzsh[bot]@users.noreply.github.com>
This commit is contained in:
ohmyzsh[bot]
2026-01-05 13:07:40 +01:00
committed by GitHub
parent 28d4ab6e98
commit 2daffdf101
4 changed files with 533 additions and 178 deletions

View File

@@ -1,49 +1,82 @@
# kube-ps1: Kubernetes prompt for bash and zsh
![GitHub Release](https://img.shields.io/github/v/release/jonmosco/kube-ps1)
[![CI](https://github.com/jonmosco/kube-ps1/actions/workflows/ci.yml/badge.svg)](https://github.com/jonmosco/kube-ps1/actions/workflows/ci.yml)
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 demo](img/kube-ps1-demo.gif)
## Installing
### MacOS
### Packages
### MacOS Brew Ports
Homebrew package manager:
```sh
brew update
brew install kube-ps1
```
$ brew update
$ brew install kube-ps1
### Arch Linux
AUR Package available at [https://aur.archlinux.org/packages/kube-ps1/](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:
```bash
plugins=(
kube-ps1
)
PROMPT='$(kube_ps1)'$PROMPT # or RPROMPT='$(kube_ps1)'
```
### From Source
## Zsh zinit plugin
### Using [zinit](https://github.com/zdharma-continuum/zinit)
Update `.zshrc` with:
```sh
zinit light jonmosco/kube-ps1
PROMPT='$(kube_ps1)'$PROMPT # or RPROMPT='$(kube_ps1)'
```
### Fig
Install `kube-ps1` in zsh, bash, or fish with one click.
<a href="https://fig.io/plugins/other/kube-ps1" target="_blank"><img src="https://fig.io/badges/install-with-fig.svg" width="120" /></a>
### From Source (git clone)
1. Clone this repository
2. Source the kube-ps1.sh in your `~/.zshrc` or your `~/.bashrc`
### Arch Linux
AUR Package available at [https://aur.archlinux.org/packages/kube-ps1/](https://aur.archlinux.org/packages/kube-ps1/).
#### Zsh
```sh
source /path/to/kube-ps1.sh
PROMPT='$(kube_ps1)'$PROMPT
PROMPT='$(kube_ps1)'$PROMPT # or RPROMPT='$(kube_ps1)'
```
#### Bash
```sh
source /path/to/kube-ps1.sh
PS1='[\u@\h \W $(kube_ps1)]\$ '
```
### Zsh Plugin Managers
#### Using [zplugin](https://github.com/zdharma/zplugin)
Update `.zshrc` with:
```sh
zplugin light jonmosco/kube-ps1
PROMPT='$(kube_ps1)'$PROMPT
```
## Requirements
The default prompt assumes you have the `kubectl` command line utility installed.
@@ -54,22 +87,23 @@ Official installation instructions and binaries are available:
If using this with OpenShift, the `oc` tool needs installed. It can be obtained
from brew ports:
```
```sh
brew install openshift-cli
```
or the source can be downloaded:
[OC Client Tools](https://www.openshift.org/download.html)
[OC Client Tools](https://github.com/okd-project/okd/releases)
Set the binary to `oc` with the following environment variable:
Set the binary to `oc` with the following variable:
```
```sh
KUBE_PS1_BINARY=oc
```
If neither binary is available, the prompt will print the following:
```
```sh
(<symbol>|BINARY-N/A:N/A)
```
@@ -90,13 +124,13 @@ tmux, and like the functionality provided by kube-ps1, checkout the
The default prompt layout is:
```
```sh
(<symbol>|<context>:<namespace>)
```
If the current-context is not set, kube-ps1 will return the following:
```
```sh
(<symbol>|N/A:N/A)
```
@@ -107,7 +141,7 @@ 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`.
```
```sh
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
@@ -116,39 +150,69 @@ kubeoff : turn off kube-ps1 status for this shell. Takes precedence over
kubeoff -g : turn off kube-ps1 status globally
```
## Symbol
The default symbols are UTF8 and should work with most fonts. If you want to use the Kubernetes and OpenShift
glyphs, you need to install a patched font that contains the glyph. [Nerd Fonts](https://www.nerdfonts.com/) provides both glyphs. Follow their installation instructions to install the patched font.
`KUBE_PS1_SYMBOL_CUSTOM` options
| Options | Symbol | Description |
| ------------- | ------ | ----------- |
| default (empty string) | ⎈ | Default symbol (Unicode `\u2388`) |
| img | ☸️ | Symbol often used to represent Kubernetes (Unicode `\u2638`) |
| oc | ![openshift-glyph](img/openshift-glyph.png) | Symbol representing OpenShift (Unicode `\ue7b7`) |
| k8s | ![k8s-glyph](img/k8s-glyph.png) | Symbol representing Kubernetes (Unicode `\ue7b7`) |
To set the symbol to one of the custom glyphs, add the following to your `~/.bashrc` or `~/.zshrc`:
```sh
KUBE_PS1_SYMBOL_CUSTOM=img
```
To set the symbol to the default, set the `KUBE_PS1_SYMBOL` to an empty string.
Heres a demo of the symbols in action:
![kube-ps1-symbols](img/kube-ps1-symbol-demo.gif)
If the font is not properly installed, and the glyph is not available, it will display an empty set of brackets or similar:
```sh
echo -n "\ue7b7"
```
## Customization
The default settings can be overridden in `~/.bashrc` or `~/.zshrc` by setting
the following environment variables:
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_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_SYMBOL_CUSTOM` | `⎈` | Change the Default prompt symbol. Unicode `\u2388`. Options are `k8s`, `img`, `oc` |
| `KUBE_PS1_SYMBOL_COLOR` | `blue` | Change the Default symbol color. |
| `KUBE_PS1_SEPARATOR` | &#124; | 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 |
| `KUBE_PS1_KUBECONFIG_SYMLINK` | `false` | Treat `KUBECONFIG` and `~/.kube/config` files as symbolic links |
For terminals that do not support UTF-8, the symbol will be replaced with the
string `k8s`.
| `KUBE_PS1_CTX_COLOR_FUNCTION` | No default, must be user supplied | Function to customize context color based on context name |
| `KUBE_PS1_HIDE_IF_NOCONTEXT` | `false` | Hide the kube-ps1 prompt if no context is set |
To disable a feature, set it to an empty string:
```
```sh
KUBE_PS1_SEPARATOR=''
```
## Colors
The default colors are set with the following environment variables:
The default colors are set with the following variables:
| Variable | Default | Meaning |
| :------- | :-----: | ------- |
@@ -166,13 +230,13 @@ namespace.
Set the variable to an empty string if you do not want color for each
prompt section:
```
```sh
KUBE_PS1_CTX_COLOR=''
```
Names are usable for the following colors:
```
```text
black, red, green, yellow, blue, magenta, cyan
```
@@ -216,6 +280,45 @@ 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.
## Dynamic Context Colors
You can set different colors for different contexts using the
`KUBE_PS1_CTX_COLOR_FUNCTION` variable. This is useful for color-coding
contexts to make production environments stand out visually.
For example, to make production contexts red and development contexts green:
```sh
function kube_ps1_ctx_color() {
local context="$1"
case "$context" in
*prod*)
echo "red"
;;
*dev*)
echo "green"
;;
*staging*|*stg*)
echo "yellow"
;;
*)
echo "cyan" # default color for other contexts
;;
esac
}
export KUBE_PS1_CTX_COLOR_FUNCTION=kube_ps1_ctx_color
```
The function receives the context name as the first parameter and should echo
the desired color name. All color options supported by `KUBE_PS1_CTX_COLOR` are
available, including named colors (black, red, green, yellow, blue, magenta,
cyan, white) and 256-color codes (0-256).
If `KUBE_PS1_CTX_COLOR_FUNCTION` is not set, kube-ps1 will use the value of
`KUBE_PS1_CTX_COLOR` (default: red).
### Bug Reports and shell configuration
Due to the vast ways of customizing the shell, please try the prompt with a
@@ -224,18 +327,28 @@ minimal configuration before submitting a bug report.
This can be done as follows for each shell before loading kube-ps1:
Bash:
```bash
```sh
bash --norc
```
Zsh:
```bash
```sh
zsh -f
or
zsh --no-rcs
```
## Contributors
For the prompt symbol, a patched font that contains the glyphs must be installed.
[Nerd Fonts Downloads](https://www.nerdfonts.com/font-downloads) provides patched
fonts containing the glyphs. Please consult their documentation for this, support
is out of scope for this project.
* [Ahmet Alp Balkan](https://github.com/ahmetb)
* Jared Yanovich
### Contributors
Thank you to everyone in the community for their contributions to kube-ps1!
<a href="https://github.com/jonmosco/kube-ps1/graphs/contributors">
<img src="https://contrib.rocks/image?repo=jonmosco/kube-ps1" />
</a>