Skip to content

Instantly share code, notes, and snippets.

@partcyborg
Created February 12, 2021 19:56
Show Gist options
  • Save partcyborg/e703895b28f355af506fcfcfe6e34ad7 to your computer and use it in GitHub Desktop.
Save partcyborg/e703895b28f355af506fcfcfe6e34ad7 to your computer and use it in GitHub Desktop.
Render `kubectl diff` in (n|)vim
#!/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