Created
February 12, 2021 19:56
-
-
Save partcyborg/e703895b28f355af506fcfcfe6e34ad7 to your computer and use it in GitHub Desktop.
Render `kubectl diff` in (n|)vim
This file contains 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 | |
# To enable this: | |
# 1) Place this script in your path | |
# 2) chmod 755 it | |
# 3) Add `export KUBECTL_EXTERNAL_DIFF=kubectl_diff_wrapper` | |
# to your shell's rc file | |
# Set this to "vim" if not using neovim | |
DIFFTOOL=nvim | |
DIFF= | |
for f in "${1}"/*; do | |
other="${2}/${f##*/}" | |
res= | |
if ! cmp -s "$f" "$other"; then | |
DIFF=1 | |
echo " - ${f##*/}" | |
$DIFFTOOL -d "$f" "$other" | |
res=$? | |
if [[ "$res" -gt 0 ]]; then | |
echo "\nDiff non-zero exit code ($res), aborting." | |
exit 2 | |
fi | |
fi | |
done | |
if [[ -z "$DIFF" ]]; then | |
echo " - No changes" | |
exit 0 | |
fi | |
exit 1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment