On Wed, 23 May 2012 13:47:22 +1000 (EST)
Tim Connors <[email protected]> wrote:

> Have you tried it?  

Yes, and wrongly, on Tuesday -- fortunately your reply showed my
mistake.  (My 'wdiff -a' input was two versions of a 'man' page that
had some control characters in it, which 'less' didn't like, and at the
time seemed like garbage.)

> Even if I unset $LESS on my system (which normally
> contains "-R"), wdiff -a automatically pages to less (hmm, maybe you
> need to set PAGER to "less" rather than "more" too).  And if you don't
> explicitly pipe to a pager and just let "wdiff -a" do it, then wdiff
> overstrikes the characters such that less (maybe you need a real
> terminal like xterm rather than something crappy like gnome-terminal)
> colourises it correctly.

Very helpful, thanks -- how little I'd looked into 'wdiff'!  This works
(no highlighting, but the text equivalent):

        # change the first 'o' from 'fortune' quote to 'oo'; compare.
        % fortune | tee /tmp/fub2 | sed 's/o/oo/1' > /tmp/fub1 ; wdiff 
/tmp/fub[12]
        [-Trooubled-]{+Troubled+} day for virgins over 16 who are beautiful and 
wealthy and live
        in eucalyptus trees.

And 'wdiff -a ...' does indeed highlight.  

The '-t' ('--terminal') switch also provides more or less the thing
desired:

        wdiff -t /tmp/fub*

Except it's not in color.  'info wdiff' shows a way (bash):

               wdiff -n \
                 -w $'\033[30;41m' -x $'\033[0m' \
                 -y $'\033[30;42m' -z $'\033[0m' \
                 ... | less -R

          This will print deleted text black on red, and inserted text
          black on green

Sometimes I don't want to see the common words, or any lines of "===="
that the '--no-common' switch outputs.  Of course a built-in switch
would be simpler; until then, for users in the same spot, a bash
function:

        # Usage:  minimal_colorwdiff file1 file2
        #         minimal_colorwdiff diff_file
        minimal_colorwdiff() { \
             { [ "$2" ] \
                && wdiff -3  -w $'\033[30;41m'  -x $'\033[0m'  \
                             -y $'\033[30;42m'  -z $'\033[0m' $1 $2 \
                || wdiff -3d -w $'\033[30;41m'  -x $'\033[0m'  \
                             -y $'\033[30;42m'  -z $'\033[0m' $1 ; \
             } | sed -n '/^$\|^=*$\|^.*-- .*++ .*/!p' ; \
        }


This one takes two args, (files to be diff'd); or one arg, (a single
diff file, in which case it'll also omit any leading line of filename
metadata).



-- 
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]

Reply via email to