Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ sudo rm /usr/local/lib/fcompare/fcompare_html_report.php
## 🚀 Usage

```bash
fcompare -r -s <source> -d <destination> -n <name> [-o <output folder>] [-x <exclude file>]
fcompare -r -s <source> -d <destination> -n <name> [-o <output folder>] [-x <exclude file>] [-P]
```

### Required arguments:
Expand All @@ -83,7 +83,8 @@ fcompare -r -s <source> -d <destination> -n <name> [-o <output folder>] [-x <exc

### Optional:

* `-r` : recursive
* `-r` : recursive
* `-P` : generate a patch(1)-compatible diff
* `-o <output folder>`: Where to store the result files
Default: current directory
* `-x <exclude file>`: exclude file (e.g. `./project/exclude.txt`)
Expand Down
28 changes: 17 additions & 11 deletions fcompare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# ─────────────────────────────────────────
# Compare two folders and generate diff report (dry-run)
# Usage: fcompare.sh -s <source> -d <destination> -n <name> [-o <output.html>] [-r]
# Usage: fcompare.sh -s <source> -d <destination> -n <name> [-o <output.html>] [-r] [-P]
# ─────────────────────────────────────────

CUSTOM_OUTPUT=""
Expand All @@ -11,16 +11,18 @@ HELPER="fcompare_html_report.php"
HELPER_LOC="/usr/local/lib/fcompare/"
HELPER_PATH="${HELPER_LOC}${HELPER}"
RECURSIVE=false
PATCH=false

# Parse options
while getopts ":s:d:n:o:x:r" opt; do
while getopts ":s:d:n:o:x:rP" opt; do
case $opt in
s) SOURCE="$OPTARG" ;;
d) TARGET="$OPTARG" ;;
n) NAME="$OPTARG" ;;
o) CUSTOM_OUTPUT="$OPTARG" ;;
x) EXCLUDE_FILE="$OPTARG" ;;
r) RECURSIVE=true ;;
P) PATCH=true ;;
\?) echo "❌ Invalid option: -$OPTARG" >&2; exit 1 ;;
:) echo "❌ Option -$OPTARG requires an argument." >&2; exit 1 ;;
esac
Expand All @@ -37,7 +39,7 @@ fi
# Validate required options
if [[ -z "$SOURCE" || -z "$TARGET" || -z "$NAME" ]]; then
echo "❌ Missing required arguments."
echo "Usage: $0 -s <source> -d <dest> -n <name> [-o <output.html>] [-r]"
echo "Usage: $0 -s <source> -d <dest> -n <name> [-o <output.html>] [-r] [-P]"
exit 1
fi

Expand Down Expand Up @@ -77,16 +79,20 @@ fi
echo "Generating $TXT_OUTPUT ..."
{
while read -r file; do
echo "=== $file ==="
if [ ! -f "$TARGET/$file" ]; then
echo "[MISSING IN TARGET]"
elif [ ! -f "$SOURCE/$file" ]; then
echo "[MISSING IN SOURCE]"
if $PATCH; then
diff -u -N "$TARGET/$file" "$SOURCE/$file"
else
diff -u "$TARGET/$file" "$SOURCE/$file" \
| grep -E '^(@@|[-+])' | grep -vE '^(---|\+\+\+)'
echo "=== $file ==="
if [ ! -f "$TARGET/$file" ]; then
echo "[MISSING IN TARGET]"
elif [ ! -f "$SOURCE/$file" ]; then
echo "[MISSING IN SOURCE]"
else
diff -u "$TARGET/$file" "$SOURCE/$file" \
| grep -E '^(@@|[-+])' | grep -vE '^(---|\+\+\+)'
fi
echo
fi
echo
done
} < "$RSYNC_RESULT" > "$TXT_OUTPUT" 2>&1

Expand Down
15 changes: 6 additions & 9 deletions fcompare_html_report.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,12 @@
$html .= "<span class='add'>" . htmlspecialchars($line) . "</span>";
} elseif (str_starts_with($line, '-')) {
$html .= "<span class='del'>" . htmlspecialchars($line) . "</span>";
} elseif (trim($line) === '') {
} elseif (str_starts_with($line, '[MISSING IN TARGET]')) {
$html .= "<span class='missing'>" . htmlspecialchars($line) . "</span>";

} elseif (trim($line) === '') {
} elseif (str_starts_with($line, '[MISSING IN SOURCE]')) {
$html .= '⚠️' . $line;
} elseif (trim($line) === '') {
$html .= "<br>";
} elseif (trim($line) === '') {
// skip blank lines
} elseif (str_starts_with($line, '[MISSING IN TARGET]')) {
$html .= "<span class='missing'>" . htmlspecialchars($line) . "</span>";
} elseif (str_starts_with($line, '[MISSING IN SOURCE]')) {
$html .= "<span class='missing'>" . htmlspecialchars($line) . "</span>";
} else {
$html .= "<span class='neutral'>" . htmlspecialchars($line) . "</span>";
}
Expand Down