diff --git a/README.md b/README.md index 57df04f..b16ff45 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ sudo rm /usr/local/lib/fcompare/fcompare_html_report.php ## 🚀 Usage ```bash -fcompare -r -s -d -n [-o ] [-x ] +fcompare -r -s -d -n [-o ] [-x ] [-P] ``` ### Required arguments: @@ -83,7 +83,8 @@ fcompare -r -s -d -n [-o ] [-x `: Where to store the result files Default: current directory * `-x `: exclude file (e.g. `./project/exclude.txt`) diff --git a/fcompare.sh b/fcompare.sh index beee62d..954c3fd 100644 --- a/fcompare.sh +++ b/fcompare.sh @@ -2,7 +2,7 @@ # ───────────────────────────────────────── # Compare two folders and generate diff report (dry-run) -# Usage: fcompare.sh -s -d -n [-o ] [-r] +# Usage: fcompare.sh -s -d -n [-o ] [-r] [-P] # ───────────────────────────────────────── CUSTOM_OUTPUT="" @@ -11,9 +11,10 @@ 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" ;; @@ -21,6 +22,7 @@ while getopts ":s:d:n:o:x:r" opt; do 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 @@ -37,7 +39,7 @@ fi # Validate required options if [[ -z "$SOURCE" || -z "$TARGET" || -z "$NAME" ]]; then echo "❌ Missing required arguments." - echo "Usage: $0 -s -d -n [-o ] [-r]" + echo "Usage: $0 -s -d -n [-o ] [-r] [-P]" exit 1 fi @@ -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 diff --git a/fcompare_html_report.php b/fcompare_html_report.php index e12231b..41a2fd4 100644 --- a/fcompare_html_report.php +++ b/fcompare_html_report.php @@ -37,15 +37,12 @@ $html .= "" . htmlspecialchars($line) . ""; } elseif (str_starts_with($line, '-')) { $html .= "" . htmlspecialchars($line) . ""; - } elseif (trim($line) === '') { - } elseif (str_starts_with($line, '[MISSING IN TARGET]')) { - $html .= "" . htmlspecialchars($line) . ""; - - } elseif (trim($line) === '') { - } elseif (str_starts_with($line, '[MISSING IN SOURCE]')) { - $html .= '⚠️' . $line; - } elseif (trim($line) === '') { - $html .= "
"; + } elseif (trim($line) === '') { + // skip blank lines + } elseif (str_starts_with($line, '[MISSING IN TARGET]')) { + $html .= "" . htmlspecialchars($line) . ""; + } elseif (str_starts_with($line, '[MISSING IN SOURCE]')) { + $html .= "" . htmlspecialchars($line) . ""; } else { $html .= "" . htmlspecialchars($line) . ""; }