forked from mk-fg/fgtk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfatrace-pipe
executable file
·34 lines (26 loc) · 907 Bytes
/
fatrace-pipe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/bin/bash
app='\S+'
pipe=/tmp/fatrace.fifo
pipe_group=wheel
[[ -z "$1" ]] && {
cat <<EOF >&2
Usage: $0 path_to_watch [app] [pipe] [pipe_group]
Tool to watch fs events from the specified
(app+)dir+mount and send them to fifo pipe.
FIFO should only be readable by root or specified group.
App argument can be a pcre fragment, default app: $app
Matching events will be sent to 'pipe' fifo, default: $pipe
Default pipe gid: ${pipe_group}
EOF
exit 1
}
[[ "$1" =~ ^/ ]] || { echo >&2 "Watched path must be absolute"; exit 1; }
cd "$1" || { echo >&2 "Unable to cd to: $1"; exit 1; }
[[ -n "$2" ]] && app=$2
[[ -n "$3" ]] && pipe=$3
mkfifo -m660 "$pipe"
chown root:"${pipe_group}" "$pipe"
trap 'rm -f "$pipe"' EXIT
# Not sure why buffering seem to happen here w/o pty wrapping
script -ef -c "fatrace -c" /dev/null 2>/dev/null |
grep --line-buffered -P '^emacs\(\d+\):\s+W\s+'"$(realpath .)/" >"$pipe"