Created
January 10, 2020 21:50
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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