{"id":13496166,"url":"https://github.com/jonmosco/kube-ps1","last_synced_at":"2025-05-13T15:10:36.922Z","repository":{"id":27042603,"uuid":"112216548","full_name":"jonmosco/kube-ps1","owner":"jonmosco","description":"Kubernetes prompt info for bash and zsh","archived":false,"fork":false,"pushed_at":"2025-03-13T18:23:01.000Z","size":7927,"stargazers_count":3648,"open_issues_count":6,"forks_count":358,"subscribers_count":36,"default_branch":"master","last_synced_at":"2025-04-23T18:55:57.015Z","etag":null,"topics":["bash","containers","kubectl","kubernetes","kubernetes-helper","prompts","sre","zsh"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jonmosco.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-11-27T15:53:46.000Z","updated_at":"2025-04-21T04:49:01.000Z","dependencies_parsed_at":"2023-01-14T05:52:21.845Z","dependency_job_id":"297d8a15-81f8-426c-a468-3fb2fb327755","html_url":"https://github.com/jonmosco/kube-ps1","commit_stats":{"total_commits":193,"total_committers":23,"mean_commits":8.391304347826088,"dds":"0.24352331606217614","last_synced_commit":"0391b238d903022dd78b40be4f2fb5bba96cc0f3"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonmosco%2Fkube-ps1","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonmosco%2Fkube-ps1/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonmosco%2Fkube-ps1/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jonmosco%2Fkube-ps1/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jonmosco","download_url":"https://codeload.github.com/jonmosco/kube-ps1/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253969248,"owners_count":21992263,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bash","containers","kubectl","kubernetes","kubernetes-helper","prompts","sre","zsh"],"created_at":"2024-07-31T19:01:43.259Z","updated_at":"2025-05-13T15:10:31.911Z","avatar_url":"https://github.com/jonmosco.png","language":"Shell","funding_links":[],"categories":["Shell","API/CLI adaptors","Plugins","CLI tools","Tools and Libraries","HarmonyOS","K8S-Tools","一、核心工具集（按场景分类）","Developer Workspaces \u0026 Productivity","☸️ Kubernetes e Cloud Native"],"sub_categories":["[Jenkins](#jenkins)","ZSH on Windows","Command Line Tools","Windows Manager","Zinit (née zplugin)","7. 测试与故障排查（验证稳定性）","Ferramentas de Debugging"],"readme":"# kube-ps1: Kubernetes prompt for bash and zsh\n\n![GitHub Release](https://img.shields.io/github/v/release/jonmosco/kube-ps1)\n[![CI](https://github.com/jonmosco/kube-ps1/actions/workflows/ci.yml/badge.svg)](https://github.com/jonmosco/kube-ps1/actions/workflows/ci.yml)\n\nA script that lets you add the current Kubernetes context and namespace\nconfigured on `kubectl` to your Bash/Zsh prompt strings (i.e. the `$PS1`).\n\nInspired by several tools used to simplify usage of `kubectl`.\n\n![prompt demo](img/kube-ps1-demo.gif)\n\n## Installing\n\n### Packages\n\n### MacOS Brew Ports\n\nHomebrew package manager:\n\n```sh\nbrew update\nbrew install kube-ps1\n```\n\n### Arch Linux\n\nAUR Package available at [https://aur.archlinux.org/packages/kube-ps1/](https://aur.archlinux.org/packages/kube-ps1/).\n\n### Oh My Zsh\n\nhttps://github.com/ohmyzsh/ohmyzsh\n\nkube-ps1 is included as a plugin in the oh-my-zsh project.  To enable it, edit your `~/.zshrc` and\nadd the plugin:\n\n```bash\nplugins=(\n  kube-ps1\n)\nPROMPT='$(kube_ps1)'$PROMPT # or RPROMPT='$(kube_ps1)'\n```\n\n## Zsh zinit plugin\n\n### Using [zinit](https://github.com/zdharma-continuum/zinit)\n\nUpdate `.zshrc` with:\n```sh\nzinit light jonmosco/kube-ps1\nPROMPT='$(kube_ps1)'$PROMPT # or RPROMPT='$(kube_ps1)'\n```\n\n### Fig\n\nInstall `kube-ps1` in zsh, bash, or fish with one click.\n\n\u003ca href=\"https://fig.io/plugins/other/kube-ps1\" target=\"_blank\"\u003e\u003cimg src=\"https://fig.io/badges/install-with-fig.svg\" /\u003e\u003c/a\u003e\n\n### From Source (git clone)\n\n1. Clone this repository\n2. Source the kube-ps1.sh in your `~/.zshrc` or your `~/.bashrc`\n\n#### Zsh\n\n```sh\nsource /path/to/kube-ps1.sh\nPROMPT='$(kube_ps1)'$PROMPT # or RPROMPT='$(kube_ps1)'\n```\n#### Bash\n\n```sh\nsource /path/to/kube-ps1.sh\nPS1='[\\u@\\h \\W $(kube_ps1)]\\$ '\n```\n\n## Requirements\n\nThe default prompt assumes you have the `kubectl` command line utility installed.\nOfficial installation instructions and binaries are available:\n\n[Install and Set up kubectl](https://kubernetes.io/docs/tasks/tools/install-kubectl/)\n\nIf using this with OpenShift, the `oc` tool needs installed.  It can be obtained\nfrom brew ports:\n\n```sh\nbrew install openshift-cli\n```\nor the source can be downloaded:\n\n[OC Client Tools](https://github.com/okd-project/okd/releases)\n\nSet the binary to `oc` with the following variable:\n\n```sh\nKUBE_PS1_BINARY=oc\n```\n\nIf neither binary is available, the prompt will print the following:\n\n```sh\n(\u003csymbol\u003e|BINARY-N/A:N/A)\n```\n\n## Helper utilities\n\nThere are several great tools that make using kubectl very enjoyable:\n\n- [`kubectx` and `kubens`](https://github.com/ahmetb/kubectx) are great for\nfast switching between clusters and namespaces.\n\n## Tmux port\n\nI have begun porting kube-ps1 to tmux as a status line plugin.  If you prefer\ntmux, and like the functionality provided by kube-ps1, checkout the\n[kube-tmux](https://github.com/jonmosco/kube-tmux) project\n\n## Prompt Structure\n\nThe default prompt layout is:\n\n```\n(\u003csymbol\u003e|\u003ccontext\u003e:\u003cnamespace\u003e)\n```\n\nIf the current-context is not set, kube-ps1 will return the following:\n\n```\n(\u003csymbol\u003e|N/A:N/A)\n```\n\n## Enabling/Disabling\n\nIf you want to stop showing Kubernetes status on your prompt string temporarily\nrun `kubeoff`. To disable the prompt for all shell sessions, run `kubeoff -g`.\nYou can enable it again in the current shell by running `kubeon`, and globally\nwith `kubeon -g`.\n\n```\nkubeon     : turn on kube-ps1 status for this shell.  Takes precedence over\n             global setting for current session\nkubeon -g  : turn on kube-ps1 status globally\nkubeoff    : turn off kube-ps1 status for this shell. Takes precedence over\n             global setting for current session\nkubeoff -g : turn off kube-ps1 status globally\n```\n\n## Symbol\n\nThe default symbols are UTF8 and should work with most fonts. If you want to use the Kubernetes and OpenShift\nglyphs, 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.\n\n`KUBE_PS1_SYMBOL_CUSTOM` options\n| Options | Symbol | Description |\n| ------------- | ------ | ----------- |\n| default (empty string) | ⎈      | Default symbol (Unicode `\\u2388`) |\n| img           | ☸️      | Symbol often used to represent Kubernetes (Unicode `\\u2638`) |\n| oc            | ![openshift-glyph](img/openshift-glyph.png) | Symbol representing OpenShift (Unicode `\\ue7b7`) |\n| k8s           | ![k8s-glyph](img/k8s-glyph.png) | Symbol representing Kubernetes (Unicode `\\ue7b7`) |\n\nTo set the symbol to one of the custom glyphs, add the following to your `~/.bashrc` or `~/.zshrc`:\n\n```sh\nKUBE_PS1_SYMBOL_CUSTOM=img\n```\n\nTo set the symbol to the default, set the `KUBE_PS1_SYMBOL` to an empty string.\n\nHeres a demo of the symbols in action:\n![kube-ps1-symbols](img/kube-ps1-symbol-demo.gif)\n\nIf the font is not properly installed, and the glyph is not available, it will display an empty set of brackets or similar:\n\n```sh\n echo -n \"\\ue7b7\"\n \n```\n\n## Customization\n\nThe default settings can be overridden in `~/.bashrc` or `~/.zshrc` by setting\nthe following variables:\n\n| Variable | Default | Meaning |\n| :------- | :-----: | ------- |\n| `KUBE_PS1_BINARY` | `kubectl` | Default Kubernetes binary |\n| `KUBE_PS1_NS_ENABLE` | `true` | Display the namespace. If set to `false`, this will also disable `KUBE_PS1_DIVIDER` |\n| `KUBE_PS1_PREFIX` | `(` | Prompt opening character  |\n| `KUBE_PS1_SYMBOL_ENABLE` | `true ` | Display the prompt Symbol. If set to `false`, this will also disable `KUBE_PS1_SEPARATOR` |\n| `KUBE_PS1_SYMBOL_PADDING` | `false` | Adds a space (padding) after the symbol to prevent clobbering prompt characters |\n| `KUBE_PS1_SYMBOL_CUSTOM` | `⎈ ` | Change the Default prompt symbol. Unicode `\\u2388`.  Options are `k8s`, `img`, `oc` |\n| `KUBE_PS1_SYMBOL_COLOR` | `blue` | Change the Default symbol color. |\n| `KUBE_PS1_SEPARATOR` | \u0026#124; | Separator between symbol and context name |\n| `KUBE_PS1_DIVIDER` | `:` | Separator between context and namespace |\n| `KUBE_PS1_SUFFIX` | `)` | Prompt closing character |\n| `KUBE_PS1_CLUSTER_FUNCTION` | No default, must be user supplied | Function to customize how cluster is displayed |\n| `KUBE_PS1_NAMESPACE_FUNCTION` | No default, must be user supplied | Function to customize how namespace is displayed |\n| `KUBE_PS1_HIDE_IF_NOCONTEXT` | `false` | Hide the kube-ps1 prompt if no context is set |\n\nTo disable a feature, set it to an empty string:\n\n```sh\nKUBE_PS1_SEPARATOR=''\n```\n\n## Colors\n\nThe default colors are set with the following variables:\n\n| Variable | Default | Meaning |\n| :------- | :-----: | ------- |\n| `KUBE_PS1_PREFIX_COLOR` | `null` | Set default color of the prompt prefix |\n| `KUBE_PS1_SYMBOL_COLOR` | `blue` | Set default color of the Kubernetes symbol |\n| `KUBE_PS1_CTX_COLOR` | `red` | Set default color of the context |\n| `KUBE_PS1_SUFFIX_COLOR` | `null` | Set default color of the prompt suffix |\n| `KUBE_PS1_NS_COLOR` | `cyan` | Set default color of the namespace |\n| `KUBE_PS1_BG_COLOR` | `null` | Set default color of the prompt background |\n\nBlue was used for the default symbol to match the Kubernetes color as closely\nas possible. Red was chosen as the context name to stand out, and cyan for the\nnamespace.\n\nSet the variable to an empty string if you do not want color for each\nprompt section:\n\n```sh\nKUBE_PS1_CTX_COLOR=''\n```\n\nNames are usable for the following colors:\n\n```\nblack, red, green, yellow, blue, magenta, cyan\n```\n\n256 colors are available by specifying the numerical value as the variable\nargument.\n\n## Customize display of cluster name and namespace\n\nYou can change how the cluster name and namespace are displayed using the\n`KUBE_PS1_CLUSTER_FUNCTION` and `KUBE_PS1_NAMESPACE_FUNCTION` variables\nrespectively.\n\nFor the following examples let's assume the following:\n\ncluster name: `sandbox.k8s.example.com`\nnamespace: `alpha`\n\nIf you're using domain style cluster names, your prompt will get quite long\nvery quickly. Let's say you only want to display the first portion of the\ncluster name (`sandbox`), you could do that by adding the following:\n\n```sh\nfunction get_cluster_short() {\n  echo \"$1\" | cut -d . -f1\n}\n\nKUBE_PS1_CLUSTER_FUNCTION=get_cluster_short\n```\n\nThe same pattern can be followed to customize the display of the namespace.\nLet's say you would prefer the namespace to be displayed in all uppercase\n(`ALPHA`), here's one way you could do that:\n\n```sh\nfunction get_namespace_upper() {\n    echo \"$1\" | tr '[:lower:]' '[:upper:]'\n}\n\nexport KUBE_PS1_NAMESPACE_FUNCTION=get_namespace_upper\n```\n\nIn 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.\n\n### Bug Reports and shell configuration\n\nDue to the vast ways of customizing the shell, please try the prompt with a\nminimal configuration before submitting a bug report.\n\nThis can be done as follows for each shell before loading kube-ps1:\n\nBash:\n\n```sh\nbash --norc\n```\n\nZsh:\n\n```sh\nzsh -f\nor\nzsh --no-rcs\n```\n\nFor the prompt symbol, a patched font that contains the glyphs must be installed.\n[Nerd Fonts Downloads](https://www.nerdfonts.com/font-downloads) provides patched\nfonts containing the glyphs.  Please consult their documentation for this, support\nis out of scope for this project.\n\n### Contributors\n\nThank you to everyone in the community for their contributions to kube-ps1! \n\n\u003ca href=\"https://github.com/jonmosco/kube-ps1/graphs/contributors\"\u003e\n  \u003cimg src=\"https://contrib.rocks/image?repo=jonmosco/kube-ps1\" /\u003e\n\u003c/a\u003e\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonmosco%2Fkube-ps1","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonmosco%2Fkube-ps1","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonmosco%2Fkube-ps1/lists"}