Skip to content

Instantly share code, notes, and snippets.

@brianoflan
Created October 30, 2017 19:08
Show Gist options
  • Save brianoflan/3e59d9a47e3288edb2724f739081eb98 to your computer and use it in GitHub Desktop.
Save brianoflan/3e59d9a47e3288edb2724f739081eb98 to your computer and use it in GitHub Desktop.
Diff two very similar directories
#!/bin/bash
IFF_ARGS='-dbB'
dir_diff() {
local a=$1
local b=$2
exit=0
rm -rf a b diff &> /dev/null || true
local thisn=a
local opposite=$b
local oppositen=b
for x in $a $b; do
(cd $x; find . -type f) | while read f; do
mkdn "$oppositen/$f"
mkdn "$thisn/$f"
[[ -e "$thisn/$f" ]] || ln -s "$(pwd)/$x/$f" "$thisn/$f"
[[ -e "$oppositen/$f" ]] || {
[[ -e $opposite/$f ]] \
&& ln -s "$(pwd)/$opposite/$f" "$oppositen/$f" \
|| mkf "$oppositen/$f" \
;
}
done
opposite=$a
oppositen=a
thisn=b
done
local diff=''
(cd a; find .) | while read f; do
[[ -d "a/$f" ]] || {
diff=$(diff $DIFF_ARGS "a/$f" "b/$f") || {
exit=$?
mkdn "diff/$f"
echo "$diff" > "diff/$f"
}
}
done
[[ -d diff ]] || mkdir diff ;
diff -r $DIFF_ARGS "$a" "$b" > diff/DIFF_REPORT.txt
return $exit
}
mkdn() {
local f=$1
local dn=$(dirname $f)
[[ -d "$dn" ]] || mkdir -p "$dn"
}
mkf() {
local f=$1
mkdn "$f"
touch "$f"
}
#
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment