diffinteractive
a unix shell command-line program
Run your favorite visual diff program on some of the files flagged by diff
-rq
.
Z%
diff -rq foo bar | diffinteractive
bbdiff foo/Makefile bar/Makefile ? y
(open in bbdiff
)bbdiff foo/out bar/out ?
(skip) Z%
The usage summary is this:
Usage:
diff -rq dir1 dir2 | diffinteractive [ -a ] [ command ]
Takes input piped from
diff
-rq
and acts on file difference lines.
For each such line, asks if you want to runbbdiff
.
Use the-a
option to openbbdiff
on every difference without asking.
Use thecommand
argument to run something other thanbbdiff
.
Here’s the diffinteractive
program:
#!/bin/zsh commandName=${0##*/} # Dave@Yost.com 2006-11-29 # http://Yost.com/computers/diffinteractive/ main() { getOptions $@ lines="$(getInputLines)" echo "$lines" | processLines } getOptions() { diffProgram=bbdiff zparseopts -D -K - a=argAll -help=argHelp if [[ $# > 1 || $#argHelp != 0 ]] then usage elif [[ $# = 1 ]] then diffProgram=$1 fi } usage() { if [[ $1 != '' ]] ; then echo 1>&2 "\n$1" ; fi echo 1>&2 " Usage: diff -rq dir1 dir2 | $commandName [ -a ] [ command ] Takes input piped from diff -rq and acts on file difference lines. For each such line, asks if you want to run $diffProgram. Use the -a option to open $diffProgram on every difference without asking. Use the command argument to run something other than $diffProgram. " exit 2 } getInputLines() { # Separator is either a tab or a space. awk -F '[ ]' ' # DY diff /^=differing ascii\/ascii/ { print $3, $4, $5 next } /^Files.* and .* differ$/ { print $2, $4 next } ' } processLines() { while true do read line if [[ -z $line ]] then break ; fi local doit= if [[ $#argAll != 0 ]] then doit=true else echo -n "$diffProgram $line ? " read < /dev/tty answer if [[ $answer = y || $answer = 'Y' ]] then doit=true fi fi if [[ -n $doit ]] then eval $diffProgram $(echo $line | awk '{ print $1, $2 }') fi done } main $@