mirror of
https://github.com/mr0xb/scripts.git
synced 2026-08-27 19:34:57 -04:00
add old scripts
This commit is contained in:
parent
1c58245cc5
commit
9c1772908b
18 changed files with 338 additions and 0 deletions
35
util/watchdir
Executable file
35
util/watchdir
Executable file
|
|
@ -0,0 +1,35 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Directory change notifier
|
||||
# Requires: inotify-tools (inotifywait) and notify-send (libnotify)
|
||||
|
||||
# If the user supplied a directory, use it. Otherwise default to ~/Downloads.
|
||||
DIR="${1:-$HOME/Downloads}"
|
||||
|
||||
# Resolve to an absolute path
|
||||
DIR="$(realpath "$DIR" 2>/dev/null)"
|
||||
|
||||
# Validate directory exists
|
||||
if [[ ! -d "$DIR" ]]; then
|
||||
echo "❌ Error: '$DIR' is not a valid directory."
|
||||
echo "Usage: $0 /path/to/directory"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check dependency
|
||||
if ! command -v inotifywait >/dev/null 2>&1; then
|
||||
echo "❌ Error: inotifywait (from inotify-tools) is required."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "👀 Watching directory: $DIR"
|
||||
echo "Press Ctrl+C to stop."
|
||||
echo
|
||||
|
||||
# Watch for changes: created, deleted, modified
|
||||
inotifywait -m -e create -e delete -e modify "$DIR" --format '%e %f' |
|
||||
while read -r event file; do
|
||||
notify-send "📂 Directory Change" "$event: $file"
|
||||
echo "$(date '+%F %T') $event $file"
|
||||
done
|
||||
|
||||
Loading…
Reference in a new issue