aboutsummaryrefslogtreecommitdiff
path: root/contrib/hldiff
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2019-06-07 11:53:42 -0400
committerDrew DeVault <sir@cmpwn.com>2019-06-07 11:54:01 -0400
commit6e61f58d8684ae8879482d371219d8ae5c00a39d (patch)
tree0df30b81471485779433e86457062a5cf2fcd0d2 /contrib/hldiff
parent0647ea64839df5ceecf3a71f672f05a589fd1409 (diff)
Rewrite Python filters in awk
Diffstat (limited to 'contrib/hldiff')
-rwxr-xr-xcontrib/hldiff39
1 files changed, 39 insertions, 0 deletions
diff --git a/contrib/hldiff b/contrib/hldiff
new file mode 100755
index 0000000..f2bda8d
--- /dev/null
+++ b/contrib/hldiff
@@ -0,0 +1,39 @@
+#!/bin/awk -f
+BEGIN {
+ bright = "\x1B[1m"
+ red = "\x1B[31m"
+ green = "\x1B[32m"
+ cyan = "\x1B[36m"
+ reset = "\x1B[0m"
+
+ hit_diff = 0
+}
+{
+ if (hit_diff == 0) {
+ if ($0 ~ /^diff /) {
+ hit_diff = 1;
+ print bright $0 reset
+ } else if ($0 ~ /^ .*\|.*(\+|-)/) {
+ left = substr($0, 0, index($0, "|")-1)
+ right = substr($0, index($0, "|"))
+ gsub(/-+/, red "&" reset, right)
+ gsub(/\++/, green "&" reset, right)
+ print left right
+ } else {
+ print $0
+ }
+ } else {
+ if ($0 ~ /^-/) {
+ print red $0 reset
+ } else if ($0 ~ /^+/) {
+ print green $0 reset
+ } else if ($0 ~ /^ /) {
+ print $0
+ } else if ($0 ~ /^@@ (-[0-9]+,[0-9]+ \+[0-9]+,[0-9]+) @@.*/) {
+ sub(/^@@ (-[0-9]+,[0-9]+ \+[0-9]+,[0-9]+) @@/, cyan "&" reset)
+ print $0
+ } else {
+ print bright $0 reset
+ }
+ }
+}