Skip to content

Instantly share code, notes, and snippets.

@sney2002
Created October 30, 2018 04:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sney2002/42253989b37b1073bdecbbac224d1d24 to your computer and use it in GitHub Desktop.
Save sney2002/42253989b37b1073bdecbbac224d1d24 to your computer and use it in GitHub Desktop.
Add color to the output of svn diff
nicediff() {
RED='\033[31m'
GREEN='\033[32m'
CYAN='\033[36m'
BOLD='\033[1;37m'
NC='\033[0m'
R_REMOVED="^\-([^-]|$)"
R_ADDED="^\+([^+]|$)"
R_AT="^\@\@ \-[0-9]+,[0-9]+ \+[0-9]+,[0-9]+ \@\@$"
R_DIFF_HEAD="^(\-\-\-|\+\+\+)[^\-\+]+$|^=+$|^Index:"
$(which svn) diff $1 | sed 's:\r::' | while IFS= read -r line; do
if [[ $line =~ $R_REMOVED ]]; then
echo -ne "$RED"
elif [[ $line =~ $R_ADDED ]]; then
echo -ne "$GREEN"
elif [[ $line =~ $R_AT ]]; then
echo -ne "$CYAN"
elif [[ $line =~ $R_DIFF_HEAD ]]; then
echo -ne "$BOLD"
fi
echo -n "$line"
echo -e "${NC}"
done
}
svn() {
case $1 in
diff)
nicediff $2 | less -R;;
*)
$(which svn) "$@";;
esac
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment