Skip to content

Instantly share code, notes, and snippets.

@BeanBagKing
Created January 20, 2017 03:17
Show Gist options
  • Save BeanBagKing/1822327b6d19424be2893e1cb5044c80 to your computer and use it in GitHub Desktop.
Save BeanBagKing/1822327b6d19424be2893e1cb5044c80 to your computer and use it in GitHub Desktop.
diffi - Better diff output script
#!/bin/bash
# diffi - Better diff output script
# BeanBagKing - https://gist.github.com/BeanBagKing
# If both arguments aren't given, print help text
if [ -z $1 ] || [ -z $2 ]; then
echo "Usage: `basename $0` [OLD] [NEW]"
exit 1
fi
# Gather Arguments
OLD=$1
NEW=$2
# Define variable to printf esc sequence, so it works on macOS/other non-GNU sed
# http://unix.stackexchange.com/questions/45924/using-sed-to-color-the-output-from-a-command-on-solaris/45954
esc=$(printf '\033')
# Put everything together
diff -u $OLD $NEW | sed -n '1,2d;/^[-+]/p' | sed -e "s/^-/${esc}[31m-${esc}[0m/" | sed -e "s/^+/${esc}[32m+${esc}[0m/"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment