Last active
June 3, 2021 08:54
-
-
Save shouya/ef46374d4987caae8b703df38efbc5d6 to your computer and use it in GitHub Desktop.
Kubectl explain with syntax highlighting and cache
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| KUBE_EXPLAIN_CACHE_DIR=$HOME/.kube/cache/explain | |
| p="$1" | |
| f="$KUBE_EXPLAIN_CACHE_DIR/$p" | |
| if [[ -z "$p" ]]; then | |
| echo "Usage: $0 <path>" | |
| echo "Example: $0 deploy.spec.template.spec.volumes" | |
| exit | |
| fi | |
| [[ -d "$KUBE_EXPLAIN_CACHE_DIR" ]] || mkdir -p "$KUBE_EXPLAIN_CACHE_DIR" | |
| if [[ -f "$f.err" ]]; then | |
| cat -- "$f.err" | |
| exit | |
| elif [[ -f "$f" ]]; then | |
| nvim -c 'set ft=man' -- "$f" | |
| exit | |
| fi | |
| kubectl explain "$p" > "$f" 2>&1 | |
| errcode="$?" | |
| if [[ "$errcode" != 0 ]]; then | |
| mv -- "$f" "$f.err" | |
| cat -- "$f.err" | |
| exit "$errcode" | |
| else | |
| nvim -c 'set ft=man' -- "$f" | |
| fi |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installation:
$PATH.chmod +x /path/to/kubectl-exp.Usage:
Whenever you type
kubectl explain <SOMETHING>, typekubectl exp <SOMETHING>instead.Screenshot: