Skip to content

Commit 0391b23

Browse files
authored
Merge pull request #192 from jonmosco/symbol_func_new
Symbol func updates, doc updates, added testing.
2 parents a9431e7 + 18af565 commit 0391b23

17 files changed

Lines changed: 288 additions & 107 deletions

.github/workflows/ci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: "CI"
2+
on: [push, pull_request]
3+
jobs:
4+
build:
5+
name: build
6+
runs-on: ubuntu-latest
7+
steps:
8+
9+
- name: Setup BATS
10+
uses: mig4/setup-bats@v1
11+
with:
12+
bats-version: 1.2.1
13+
14+
- name: Check out code
15+
uses: actions/checkout@v1
16+
17+
- name: kube-ps1 test
18+
run: bats test/kube-ps1.bats

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
### [UNRELEASED]
44

5+
* symbol function cleanup and simplification ([#165](https://github.com/jonmosco/kube-ps1/issues/165))
6+
* Added 2 new glyphs for the symbol
7+
* The arguments to customize the symbol now include `k8s`, `oc`, and `img`. The default is ``.
8+
* cleanup of the codebase to reduce environment variable clutter
9+
* Some README cleanups.
10+
* Implemented testing with bats
11+
512
## 0.8.0 (11/22/22)
613

714
Lots of updates and changes in this long overdue release. Hopefully this summary will include the major

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
Contributing to kube-ps1
22
========================
3+
4+
Changes are welcome! Please read the [bug reports and shell configuration](#bug-reports-and-shell-configuration) section before submitting a bug report.
5+
A good deal of the problems experienced with kube-ps1 are due to the vast ways of customizing the shell.
6+
Please try the prompt with a minimal configuration before submitting a bug report.

README.md

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
# kube-ps1: Kubernetes prompt for bash and zsh
22

3+
![GitHub Release](https://img.shields.io/github/v/release/jonmosco/kube-ps1)
4+
[![CI](https://github.com/jonmosco/kube-ps1/actions/workflows/ci.yml/badge.svg)](https://github.com/jonmosco/kube-ps1/actions/workflows/ci.yml)
5+
36
A script that lets you add the current Kubernetes context and namespace
47
configured on `kubectl` to your Bash/Zsh prompt strings (i.e. the `$PS1`).
58

69
Inspired by several tools used to simplify usage of `kubectl`.
710

8-
![prompt](img/screenshot2.png)
9-
10-
![prompt_sol_light](img/screenshot-sol-light.png)
11-
12-
![prompt_img](img/screenshot-img.png)
13-
14-
![prompt demo](img/kube-ps1.gif)
11+
![prompt demo](img/kube-ps1-demo.gif)
1512

1613
## Installing
1714

18-
### Package managers
15+
### Packages
1916

2017
### MacOS Brew Ports
2118

@@ -27,6 +24,7 @@ brew install kube-ps1
2724
```
2825

2926
### Arch Linux
27+
3028
AUR Package available at [https://aur.archlinux.org/packages/kube-ps1/](https://aur.archlinux.org/packages/kube-ps1/).
3129

3230
### Oh My Zsh
@@ -40,12 +38,10 @@ add the plugin:
4038
plugins=(
4139
kube-ps1
4240
)
43-
4441
PROMPT='$(kube_ps1)'$PROMPT # or RPROMPT='$(kube_ps1)'
4542
```
4643

47-
48-
## Zsh Plugin Managers
44+
## Zsh zinit plugin
4945

5046
### Using [zinit](https://github.com/zdharma-continuum/zinit)
5147

@@ -57,23 +53,23 @@ PROMPT='$(kube_ps1)'$PROMPT # or RPROMPT='$(kube_ps1)'
5753

5854
### Fig
5955

60-
[Fig](https://fig.io) adds apps, shortcuts, and autocomplete to your existing terminal.
61-
6256
Install `kube-ps1` in zsh, bash, or fish with one click.
6357

6458
<a href="https://fig.io/plugins/other/kube-ps1" target="_blank"><img src="https://fig.io/badges/install-with-fig.svg" /></a>
6559

66-
### From Source
60+
### From Source (git clone)
6761

6862
1. Clone this repository
6963
2. Source the kube-ps1.sh in your `~/.zshrc` or your `~/.bashrc`
7064

7165
#### Zsh
66+
7267
```sh
7368
source /path/to/kube-ps1.sh
7469
PROMPT='$(kube_ps1)'$PROMPT # or RPROMPT='$(kube_ps1)'
7570
```
7671
#### Bash
72+
7773
```sh
7874
source /path/to/kube-ps1.sh
7975
PS1='[\u@\h \W $(kube_ps1)]\$ '
@@ -135,31 +131,6 @@ If the current-context is not set, kube-ps1 will return the following:
135131
(<symbol>|N/A:N/A)
136132
```
137133

138-
## Symbols
139-
140-
The default symbols are UTF8 and should work with most fonts. Due to differences
141-
in font and terminal spacing, a `KUBE_PS1_SYMBOL_PADDING` option is available to provide an extra space
142-
after the symbol.
143-
144-
In order to have the OpenShift icon, a patched font that contains the glyph must
145-
be installed. [Nerd Fonts](https://www.nerdfonts.com/) provides an OpenShift icon.
146-
Follow the install directions (out of scope for this project) to install a patched
147-
font.
148-
149-
Once installed and the font is made active in a terminal session, test to see if the symbol is available:
150-
151-
![prompt openshift na](img/screenshot-oc-na.png)
152-
153-
If the symbol is not available, it will display an empty set of brackets or similar:
154-
```sh
155-
echo -n "\ue7b7"
156-
157-
```
158-
159-
Below is a screenshot of the OpenShift symbol using the Inconsolata font from Nerd Fonts:
160-
161-
![prompt openshift](img/screenshot-oc.png)
162-
163134
## Enabling/Disabling
164135

165136
If you want to stop showing Kubernetes status on your prompt string temporarily
@@ -176,6 +147,37 @@ kubeoff : turn off kube-ps1 status for this shell. Takes precedence over
176147
kubeoff -g : turn off kube-ps1 status globally
177148
```
178149

150+
## Symbol
151+
152+
The default symbols are UTF8 and should work with most fonts. If you want to use the Kubernetes and OpenShift
153+
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.
154+
155+
`KUBE_PS1_SYMBOL_CUSTOM` options
156+
| Options | Symbol | Description |
157+
| ------------- | ------ | ----------- |
158+
| default (empty string) || Default symbol (Unicode `\u2388`) |
159+
| img | ☸️ | Symbol often used to represent Kubernetes (Unicode `\u2638`) |
160+
| oc | ![openshift-glyph](img/openshift-glyph.png) | Symbol representing OpenShift (Unicode `\ue7b7`) |
161+
| k8s | ![k8s-glyph](img/k8s-glyph.png) | Symbol representing Kubernetes (Unicode `\ue7b7`) |
162+
163+
To set the symbol to one of the custom glyphs, add the following to your `~/.bashrc` or `~/.zshrc`:
164+
165+
```sh
166+
KUBE_PS1_SYMBOL_CUSTOM=img
167+
```
168+
169+
To set the symbol to the default, set the `KUBE_PS1_SYMBOL` to an empty string.
170+
171+
Heres a demo of the symbols in action:
172+
![kube-ps1-symbols](img/kube-ps1-symbol-demo.gif)
173+
174+
If the font is not properly installed, and the glyph is not available, it will display an empty set of brackets or similar:
175+
176+
```sh
177+
echo -n "\ue7b7"
178+
179+
```
180+
179181
## Customization
180182

181183
The default settings can be overridden in `~/.bashrc` or `~/.zshrc` by setting
@@ -188,20 +190,17 @@ the following variables:
188190
| `KUBE_PS1_PREFIX` | `(` | Prompt opening character |
189191
| `KUBE_PS1_SYMBOL_ENABLE` | `true ` | Display the prompt Symbol. If set to `false`, this will also disable `KUBE_PS1_SEPARATOR` |
190192
| `KUBE_PS1_SYMBOL_PADDING` | `false` | Adds a space (padding) after the symbol to prevent clobbering prompt characters |
191-
| `KUBE_PS1_SYMBOL_DEFAULT` | `` | Default prompt symbol. Unicode `\u2388` |
192-
| `KUBE_PS1_SYMBOL_USE_IMG` | `false` | ☸️ , Unicode `\u2638` as the prompt symbol |
193+
| `KUBE_PS1_SYMBOL_CUSTOM` | `` | Change the Default prompt symbol. Unicode `\u2388`. Options are `k8s`, `img`, `oc` |
194+
| `KUBE_PS1_SYMBOL_COLOR` | `blue` | Change the Default symbol color. |
193195
| `KUBE_PS1_SEPARATOR` | &#124; | Separator between symbol and context name |
194196
| `KUBE_PS1_DIVIDER` | `:` | Separator between context and namespace |
195197
| `KUBE_PS1_SUFFIX` | `)` | Prompt closing character |
196198
| `KUBE_PS1_CLUSTER_FUNCTION` | No default, must be user supplied | Function to customize how cluster is displayed |
197199
| `KUBE_PS1_NAMESPACE_FUNCTION` | No default, must be user supplied | Function to customize how namespace is displayed |
198200

199-
For terminals that do not support UTF-8, the symbol will be replaced with the
200-
string `k8s`.
201-
202201
To disable a feature, set it to an empty string:
203202

204-
```
203+
```sh
205204
KUBE_PS1_SEPARATOR=''
206205
```
207206

@@ -225,7 +224,7 @@ namespace.
225224
Set the variable to an empty string if you do not want color for each
226225
prompt section:
227226

228-
```
227+
```sh
229228
KUBE_PS1_CTX_COLOR=''
230229
```
231230

@@ -283,23 +282,29 @@ minimal configuration before submitting a bug report.
283282
This can be done as follows for each shell before loading kube-ps1:
284283

285284
Bash:
285+
286286
```sh
287287
bash --norc
288288
```
289289

290290
Zsh:
291+
291292
```sh
292293
zsh -f
293294
or
294295
zsh --no-rcs
295296
```
296297

297-
For the OpenShift symbol, a patched font that contains the icon must be installed.
298+
For the prompt symbol, a patched font that contains the glyphs must be installed.
298299
[Nerd Fonts Downloads](https://www.nerdfonts.com/font-downloads) provides patched
299-
fonts containing the symbol. Please consult their documentation for this, support
300+
fonts containing the glyphs. Please consult their documentation for this, support
300301
is out of scope for this project.
301302

302303
### Contributors
303304

304-
* [Ahmet Alp Balkan](https://github.com/ahmetb)
305-
* Jared Yanovich
305+
Thank you to everyone in the community for their contributions to kube-ps1!
306+
307+
<a href="https://github.com/jonmosco/kube-ps1/graphs/contributors">
308+
<img src="https://contrib.rocks/image?repo=jonmosco/kube-ps1" />
309+
</a>
310+

img/k8s-glyph.png

1.62 KB
Loading

img/kube-ps1-demo.gif

95.7 KB
Loading

img/kube-ps1-symbol-demo.gif

64.8 KB
Loading

img/openshift-glyph.png

1.48 KB
Loading

img/screenshot-img.png

-19.1 KB
Binary file not shown.

img/screenshot-oc-na.png

-4.25 KB
Binary file not shown.

0 commit comments

Comments
 (0)