aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDuncaen <mail@duncano.de>2017-02-13 01:28:10 +0100
committerDuncaen <mail@duncano.de>2017-02-13 01:28:10 +0100
commit5eafdce461abbc8f1d34fd0d530c08bb883b5bc1 (patch)
tree654b17cd111f8e7f9561b7d9d344da90b63d2394
parent1b46c312bf8f740721634869b35a210567946494 (diff)
downloaddotfiles-5eafdce461abbc8f1d34fd0d530c08bb883b5bc1.tar.gz
bin/yiff: import Ypnoses awk version
-rwxr-xr-xbin/yiff28
1 files changed, 16 insertions, 12 deletions
diff --git a/bin/yiff b/bin/yiff
index 24759fe..287a1aa 100755
--- a/bin/yiff
+++ b/bin/yiff
@@ -1,14 +1,18 @@
-#!/usr/bin/mksh
+#!/usr/bin/awk -f
+# yiff - colored diff
# Script by Ypnose - http://ywstd.fr
-while IFS=$'\n' read -r LINE; do
- CHAR="${LINE::1}"
- case $CHAR in
- \-) print -- "\033[1;31m${LINE}\033[0m" ;;
- \+) print -- "\033[0;32m${LINE}\033[0m" ;;
- \@) print -- "\033[1;35m${LINE}\033[0m" ;;
- *) print -- "$LINE" ;;
- esac
-done
-
-exit
+BEGIN { FS="\n" }
+symb = substr($0,1,1) {
+ # Highlight end line space(s)/tab(s)
+ gsub(/[\t ]+$/,"\033[0;41m \033[0m")
+ if (symb == "@") {
+ printf("\033[1;35m%s\033[0m\n", $0)
+ } else if (symb == "-") {
+ printf("\033[0;31m%s\033[0m\n", $0)
+ } else if (symb == "+") {
+ printf("\033[0;32m%s\033[0m\n", $0)
+ } else {
+ printf("%s\n", $0)
+ }
+}