dot/shell-rc: Colourize `diff' output similarly to `grep'.
authorMark Wooding <mdw@distorted.org.uk>
Fri, 2 Aug 2019 19:38:05 +0000 (20:38 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 3 Aug 2019 02:14:21 +0000 (03:14 +0100)
There's a problem here because of a `zsh' bug:

$ diff -u <(thing) <(thong) | blah
diff: /proc/self/fd/13: No such file or directory
diff: /proc/self/fd/14: No such file or directory

caused by the process-substitution pipes being lost somewhere.

Work around this as (a)

$ diff -u =(thing) =(thong) | blah

(produces temporary files), or (b)

$ { diff -u <(thing) <(thong) } | blah

(extra typing).

dot/shell-rc

index 965e8ab..aad0918 100644 (file)
@@ -163,6 +163,21 @@ alias egrep="greplike egrep"
 alias fgrep="greplike fgrep"
 alias zgrep="greplike zgrep"
 
+## Arrange for `diff' output to be in colour.
+export DIFF_COLORS="hd=1:ln=36:ad=32:de=31"
+difflike () {
+  local diff=$1; shift
+  if [ -t 1 ]; then
+    command $diff \
+           ${DIFF_COLORS+--color=always} \
+           ${DIFF_COLORS+--palette="$DIFF_COLORS"} \
+           "$@" | mdw-pager
+  else
+    command $diff "$@" | cat
+  fi
+}
+alias diff="difflike diff"
+
 ###--------------------------------------------------------------------------
 ### Other hacks.