Created
October 30, 2018 04:16
-
-
Save sney2002/42253989b37b1073bdecbbac224d1d24 to your computer and use it in GitHub Desktop.
Add color to the output of svn diff
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
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