From: Mark Wooding Date: Fri, 2 Aug 2019 19:38:05 +0000 (+0100) Subject: dot/shell-rc: Colourize `diff' output similarly to `grep'. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/profile/commitdiff_plain/049cd0157dcb6204cc0f90b7c54dd1b10de34566?ds=sidebyside dot/shell-rc: Colourize `diff' output similarly to `grep'. 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). --- diff --git a/dot/shell-rc b/dot/shell-rc index 965e8ab..aad0918 100644 --- a/dot/shell-rc +++ b/dot/shell-rc @@ -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.