Created
January 20, 2017 03:17
-
-
Save BeanBagKing/1822327b6d19424be2893e1cb5044c80 to your computer and use it in GitHub Desktop.
diffi - Better diff output script
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 | |
# 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