diff options
author | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-09-14 12:52:05 -0400 |
---|---|---|
committer | Luke Shumaker <lukeshu@sbcglobal.net> | 2016-09-14 12:52:05 -0400 |
commit | 90120f629170cfdc9b14a1901c59c48905553a1d (patch) | |
tree | 7b851feb7c150c6ea99d4928de888295b4c7b7fa /.config/bash/rc.d/10_aliases.sh | |
parent | e34d9187fb6061e612bf8e5b8bd65698f9eefdcc (diff) |
bash: have wdiff and chardiff obey colordiffrc
Diffstat (limited to '.config/bash/rc.d/10_aliases.sh')
-rw-r--r-- | .config/bash/rc.d/10_aliases.sh | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/.config/bash/rc.d/10_aliases.sh b/.config/bash/rc.d/10_aliases.sh index 1b25f93..a4ab60e 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 |