https://github.com/jhrv/kubeaware
kubernetes context awareness
https://github.com/jhrv/kubeaware
bash kubectl kubernetes ps1 zsh
Last synced: about 1 year ago
JSON representation
kubernetes context awareness
- Host: GitHub
- URL: https://github.com/jhrv/kubeaware
- Owner: jhrv
- Created: 2018-02-16T16:05:50.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2019-01-31T07:02:58.000Z (over 7 years ago)
- Last Synced: 2025-04-13T22:15:31.163Z (about 1 year ago)
- Topics: bash, kubectl, kubernetes, ps1, zsh
- Language: Shell
- Homepage:
- Size: 108 KB
- Stars: 11
- Watchers: 2
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# kubeaware
A simpler Kubernetes context awareness helper for bash and zsh
Complements the [kubectx and kubens tools](https://github.com/ahmetb/kubectx) by [ahmetb](https://github.com/ahmetb)
## Usage

```
Usage: kube[un]aware [-g | --global] [-h | --help]
With no arguments, turn on/off kubeaware for this shell instance instance (default).
-g --global turn on kubeawareness globally
-h --help print this message
```
## Installation
### Bash
```
source kubeaware.sh
export PS1="[your prompt] \$(kubeaware_prompt)$ "
```

### Zsh
```
source kubeaware.sh
PROMPT='$(kubeaware_prompt) '$PROMPT
```
Include this in your `~/.bashrc` or `~/.zshrc`to load each time you start a new shell
### Remove Kubernetes-logo
Add the following line after `source`, if you want to remove the Kubernetes-logo:
```
unset KUBE_SYMBOL PRE_SYMBOL POST_SYMBOL
```
## How it works
When kubeaware.sh is sourced, mainly two things happen:
- You load a set of helper functions, most importantly `kubeaware` which is used in your `$PS1` environment variable
- The environment variable `$PROMPT_COMMAND` in bash is patched with the function that gets the context info from Kubernetes. For ZSH the functionality is added via add-zsh-hook precmd.
The function(s) included in `$PROMPT_COMMAND` is executed each time your shell runs a command.
The function included by kubeaware will fetch the information from the `KUBECONFIG` file (via `kubectl config`). This will only happen if `KUBECONFIG` has changed since last time it was checked.
## Acknowledgements
Heavily inspired by [kube-ps1](https://github.com/jonmosco/kube-ps1) by [jonmosco](https://github.com/jonmosco), and aims to contain only a subset of the features
## Contributors
- [Frode Sundby](https://github.com/frodesundby)
- [Vegar Sechmann Molvig](https://github.com/VegarM)
- [Kyrre Havik Eriksen](https://github.com/kyrremann)
## Known issues
Has not been tested versions of bash < 4.x, so there might be compatability issues if you are running an older version