Skip to content

Instantly share code, notes, and snippets.

@dcmbrown
Last active September 27, 2021 16:17
Show Gist options
  • Save dcmbrown/e104a99938fdbdaa51e454b882e68983 to your computer and use it in GitHub Desktop.
Save dcmbrown/e104a99938fdbdaa51e454b882e68983 to your computer and use it in GitHub Desktop.
Bash function to differentiate the contents of the current directory with another. Creates folder of diffs in ~/difftree/<dirname>
# diff the files in any two directories
function difftree ()
{
if [ $# -eq 0 ]; then
echo "DIFFTREE - Be in the source directory to compare."
echo " usage: difftree <path to directory to compare to>"
return 1
fi
here=`pwd`
there=$1
diffhome="${HOME}/difftree"
diffbase=`basename $here`
if [ ! -d ${diffhome}/${diffbase} ]; then
mkdir -p ${diffhome}/${diffbase}
fi
for a in *; do
if [ -d "$a" ]; then
echo "Looking at directory: $a"
for b in `find "$a"`; do
if [ -d "$b" ]; then
if [ ! -d "${diffhome}/${diffbase}/$b" ]; then
mkdir "${diffhome}/${diffbase}/`echo $b`";
fi;
fi;
if [ -e "${there}/`echo $b`" ]; then
if [ ! -d "${there}/`echo $b`" ]; then
diff -b "$b" "${there}/`echo $b`" >> "${diffhome}/${diffbase}/`echo $b`.diff";
fi;
else
echo >> "${diffhome}/${diffbase}/`echo $b`.does_not_exist"
fi;
done
else
echo "Looking at file: $a"
diff -b "$a" "${there}/`echo $a`" >> "${diffhome}/${diffbase}/`echo $a`.diff";
fi
done
echo "Diff'd files are in ${diffhome}/${diffbase}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment