From fe1fa83844111b3fcc49513e19304aab6ce89a78 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 14 Sep 2016 12:52:05 -0400 Subject: bash: have wdiff and chardiff obey colordiffrc --- .config/bash/rc.d/10_aliases.sh | 42 +++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/.config/bash/rc.d/10_aliases.sh b/.config/bash/rc.d/10_aliases.sh index da214e9..2e28a5d 100644 --- a/.config/bash/rc.d/10_aliases.sh +++ b/.config/bash/rc.d/10_aliases.sh @@ -22,15 +22,20 @@ if [ -x "`which dircolors`" ]; then wdiff() { if [[ -t 1 ]]; then - local red="$(tput setaf 1)" - local blue="$(tput setaf 4)" - local bold="$(tput bold)" - local reset="$(tput sgr0)" + local old new off + if type colordiff &>/dev/null; then + eval "$(colordiff <(echo old) <(echo new)|sed -rn 's@(.*)[<>] (old|new)(.*)@\2='\''\1'\''\noff='\''\3'\''\n@p')" + else + new="$(tput setaf 2)" + old="$(tput setaf 1)" + off="$(tput sgr0)" + fi command wdiff \ - -w "$bold$red[-" \ - -x "-]$reset" \ - -y "$bold$blue{+" \ - -z "+}$reset" "$@" + -w "$old[-" \ + -x "-]$off" \ + -y "$new{+" \ + -z "+}$off" \ + "$@" else command wdiff "$@" fi @@ -38,15 +43,20 @@ if [ -x "`which dircolors`" ]; then chardiff() { if [[ -t 1 ]]; then - local red="$(tput setaf 1)" - local blue="$(tput setaf 4)" - local bold="$(tput bold)" - local reset="$(tput sgr0)" + local old new off + if type colordiff &>/dev/null; then + eval "$(colordiff <(echo old) <(echo new)|sed -rn 's@(.*)[<>] (old|new)(.*)@\2='\''\1'\''\noff='\''\3'\''\n@p')" + else + new="$(tput setaf 2)" + old="$(tput setaf 1)" + off="$(tput sgr0)" + fi command chardiff \ - -w "$bold$red[-" \ - -x "-]$reset" \ - -y "$bold$blue{+" \ - -z "+}$reset" "$@" + -w "$old[-" \ + -x "-]$off" \ + -y "$new{+" \ + -z "+}$off" \ + "$@" else command chardiff "$@" fi -- cgit v1.1-4-g5e80