68f809448a08d2c93d13650157fd0500a329a16a

Author
Raphaël Pinson <github+aem1eeshi1@raphink.net>
Committer
GitHub <noreply@github.com>
Date

Message

kubectl: add wrappers for colorized output in JSON and YAML (#9316)

Co-authored-by: Marc Cornellà <marc.cornella@live.com>

Diff

 1diff --git a/plugins/kubectl/README.md b/plugins/kubectl/README.md
 2index ee05a8af119b40e589f0e0e57e06cc7c6b67544f..84f5f8d897aa6672914398059c99c25483c4ee16 100644
 3--- a/plugins/kubectl/README.md
 4+++ b/plugins/kubectl/README.md
 5@@ -106,3 +106,11 @@ plugins=(... kubectl)
 6 | kdelss  | `kubectl delete statefulset`        | Delete the statefulset                                                                           |
 7 | ksss    | `kubectl scale statefulset`         | Scale a statefulset                                                                              |
 8 | krsss   | `kubectl rollout status statefulset`| Check the rollout status of a deployment                                                         |
 9+
10+## Wrappers
11+
12+This plugin provides 3 wrappers to colorize kubectl output in JSON and YAML using various tools (which must be installed):
13+
14+- `kj`: JSON, colorized with [`jq`](https://stedolan.github.io/jq/).
15+- `kjx`: JSON, colorized with [`fx`](https://github.com/antonmedv/fx).
16+- `ky`: YAML, colorized with [`yh`](https://github.com/andreazorzetto/yh).
17diff --git a/plugins/kubectl/kubectl.plugin.zsh b/plugins/kubectl/kubectl.plugin.zsh
18index 647d029c191426a451919f7811f2896727ba4d9e..6292a0b2f2982629c0b2c9e7c8999793aba811f2 100644
19--- a/plugins/kubectl/kubectl.plugin.zsh
20+++ b/plugins/kubectl/kubectl.plugin.zsh
21@@ -150,3 +150,19 @@ alias kepvc='kubectl edit pvc'
22 alias kdpvc='kubectl describe pvc'
23 alias kdelpvc='kubectl delete pvc'
24 
25+# Colored JSON output
26+kj() {
27+  kubectl "$@" -o json | jq
28+}
29+compdef kj=kubectl
30+
31+kjx() {
32+  kubectl "$@" -o json | fx
33+}
34+compdef kjx=kubectl
35+
36+# Colored YAML output
37+ky() {
38+  kubectl "$@" -o yaml | yh
39+}
40+compdef ky=kubectl