From fb26ff880cb1e7461b5adcfbcea972dc658b59bf Mon Sep 17 00:00:00 2001 From: Sorin Ionescu Date: Wed, 28 Dec 2011 10:34:23 -0500 Subject: [PATCH] Improved handling of color diff. --- alias.zsh | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/alias.zsh b/alias.zsh index 3bcd21e8..3ac3c0c7 100644 --- a/alias.zsh +++ b/alias.zsh @@ -80,17 +80,27 @@ fi # Diff/Make if zstyle -t ':omz:alias:diff' color; then - if (( $+commands[colordiff] )); then - alias diff='colordiff -u' - compdef colordiff=diff - elif (( $+commands[git] )); then - function diff() { - git --no-pager diff --color=always --no-ext-diff --no-index "$@"; - } - compdef _git diff=git-diff - else - alias diff='diff -u' - fi + function diff() { + if (( $+commands[colordiff] )); then + "$commands[diff]" --unified "$@" | colordiff --difftype diffu + elif (( $+commands[git] )); then + git --no-pager diff --color=auto --no-ext-diff --no-index "$@" + else + "$commands[diff]" --unified "$@" + fi + } + + function wdiff() { + if (( $+commands[wdiff] )) && (( $+commands[colordiff] )); then + "$commands[diff]" --unified "$@" | "$commands[wdiff]" --diff-input --avoid-wraps | colordiff --difftype wdiff + elif (( $+commands[git] )); then + git --no-pager diff --color=auto --no-ext-diff --no-index --word-diff "$@" + elif (( $+commands[wdiff] )); then + "$commands[diff]" --unified "$@" | "$commands[wdiff]" --diff-input --avoid-wraps + else + print "zsh: command not found: $0" >&2 + fi + } if (( $+commands[colormake] )); then alias make='colormake'