From bc79a9f65ba9f9fdb308b4a8eb75d0ca4e692463 Mon Sep 17 00:00:00 2001 From: Michael Hunteman Date: Thu, 31 Aug 2023 18:56:05 -0500 Subject: Add aerc filters --- .config/aerc/filters/hldiff | 46 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 .config/aerc/filters/hldiff (limited to '.config/aerc/filters/hldiff') diff --git a/.config/aerc/filters/hldiff b/.config/aerc/filters/hldiff new file mode 100755 index 0000000..dc8c727 --- /dev/null +++ b/.config/aerc/filters/hldiff @@ -0,0 +1,46 @@ +#!/usr/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) { + # Strip carriage returns from line + gsub(/\r/, "", $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 { + # Strip carriage returns from line + gsub(/\r/, "", $0) + + 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 + } + } +} -- cgit v1.2.3