add dirdiff(1) Reference: /n/atom/patch/applied/dirdiff Date: Thu Mar 12 17:38:25 CET 2015 Signed-off-by: quanstro@quanstro.net --- /rc/bin/dirdiff Thu Jan 1 00:00:00 1970 +++ /rc/bin/dirdiff Thu Mar 12 17:38:09 2015 @@ -0,0 +1,48 @@ +#!/bin/rc + +# +# treat lists as sets +# ∩cl is A\B union B\A +# listminus is the set relative complement A \ B) + +fn ∩ {echo $$1 $$2 | sed 's/ /\n/g' | sort | uniq -d} +fn not∩ {echo $$1 $$2 | sed 's/ /\n/g' | sort | uniq -u} +fn listminus {c=`{∩ $1 $2} not∩ c $1} + +flagfmt='a,d' +args='[old [new]]' +if(! eval `''{aux/getflags $*}){ + aux/usage + exit usage +} +switch($#*){ +case 2 + old=$1 + new=$2 +case 1 + old=$1 + new=`{yesterday $1} +case 0 + old=. + new=`{yesterday .} +case * + aux/usage + exit usage +} + +# directory differences +new=`{cd $new && echo *} +old=`{cd $old && echo *} + +switch($#flaga ^ $#flagd){ +case 11 + echo 'added=(' `{listminus old new} ')' + echo 'deleted=(' `{listminus new old} ')' +case 10 + echo `{listminus old new} +case 01 + echo `{listminus new old} +case 00 + echo 'added=(' `{listminus old new} ')' + echo 'deleted=(' `{listminus new old} ')' +} --- /sys/man/1/dirdiff Thu Jan 1 00:00:00 1970 +++ /sys/man/1/dirdiff Thu Mar 12 17:38:10 2015 @@ -0,0 +1,48 @@ +.TH DIRDIFF 1 +.SH NAME +dirdiff \- directory file differences +.SH SYNOPSIS +.B dirdiff +[ +.B -ad +] [ +.I old +[ +.I new +] ] +.SH DESCRIPTION +.I Dirdiff +computes the difference of two directories and outputs +two +.IR rc (1) +lists, +.L added, +and +.L deleted +which describe the differences. With the +.B -d +flag, the deleted files are output; +with +.BR -a , +the added files are output. These flags may be combined. +The default new directory is +.L . +while the default old directory is yesterday's version of +the same directory. Files that are different are not +considered. +.SH EXAMPLE +.IP +.EX +; dirdiff +added=( xmlheap.c xmlmalloc.c ) +deleted=( heap.c xmlfree.c ) +; dirdiff -d +heap.c xmlfree.c +.EE +.SH SOURCE +.B /rc/bin/dirdiff +.SH SEE ALSO +.IR rc (1), +.IR yesterday (1) +.SH BUGS +Beware of directories with frogs.