From e8cf42f2f17151378574ee5b50f29904a1067bee Mon Sep 17 00:00:00 2001 From: Lukasz Kasprzak Date: Tue, 19 May 2026 18:38:39 +0200 Subject: added readme --- watchdir | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100755 watchdir (limited to 'watchdir') diff --git a/watchdir b/watchdir new file mode 100755 index 0000000..3499bf8 --- /dev/null +++ b/watchdir @@ -0,0 +1,42 @@ +#!/bin/sh +# Usage: watchdir [DIR] [LOGFILE] +# Recursively logs file additions/modifications/deletions. + +set -eu + +DIR="${1:-$PWD}" +LOG="${2:-$DIR/changes.log}" + +if [ ! -d "$DIR" ]; then + printf 'Not a directory: %s\n' "$DIR" >&2 + exit 1 +fi + +DIR=$(readlink -f "$DIR") +LOG=$(readlink -f "$LOG") + +# Exclude patterns (POSIX extended regex, OR-joined). +# Append more lines below to extend. +EXCLUDES="${LOG}\$" +EXCLUDES="${EXCLUDES}|/\\.git(/|\$)" +# EXCLUDES="${EXCLUDES}|/node_modules(/|\$)" +# EXCLUDES="${EXCLUDES}|\\.swp\$" +EXCLUDE_RE="($EXCLUDES)" + +printf 'Watching: %s\n' "$DIR" +printf 'Logging to: %s\n' "$LOG" + +inotifywait -mr \ + --exclude "$EXCLUDE_RE" \ + -e close_write,create,delete,moved_to,moved_from \ + --format '%T|%e|%w%f' --timefmt '%F %T' \ + "$DIR" | +while IFS='|' read -r ts ev path; do + case "$ev" in + CREATE*|MOVED_TO*) action=added ;; + CLOSE_WRITE*) action=modified ;; + DELETE*|MOVED_FROM*) action=deleted ;; + *) action="$ev" ;; + esac + printf '%s|%s|%s\n' "$ts" "$action" "$path" >> "$LOG" +done -- cgit v1.3