Skip to content

Instantly share code, notes, and snippets.

@ksemel
Created January 10, 2020 21:50
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ksemel/760f1950f0a8880c7071de41104b1769 to your computer and use it in GitHub Desktop.
Save ksemel/760f1950f0a8880c7071de41104b1769 to your computer and use it in GitHub Desktop.
Bash: Check for diffs, and only open the merge tool if diffs are found.
#!/bin/bash
#
# Check for diffs, and only open the merge tool if diffs are found.
#
dir=$FIRSTDIRECTORY
dir2=$SECONDDIRECTORY
cd "$dir"
declare -a files=($(ls -d *))
for file in "${files[@]}"; do
if [ ! -f "$dir2/$file" ]; then
echo "Copying $dir2/$file"
cp $dir/$file $dir2/$file
else
# Basic Diffing
diffresult=$(diff --ignore-space-change "$dir/$file" "$dir2/$file")
if [ "$diffresult" != "" ]; then
# Interactive merge for conflicts
ksdiff --wait "$dir/$file" "$dir2/$file" &
PID=$!
fi
fi
if [ "$PID" != "" ]; then
wait $PID
fi
PID=""
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment