25 lines
400 B
Nix
25 lines
400 B
Nix
pkgs: {
|
|
cmd,
|
|
setup ? null,
|
|
stop ? null,
|
|
process ? null,
|
|
view ? null,
|
|
}:
|
|
pkgs.writeShellScriptBin "watch" ''
|
|
path=''${1:-.}
|
|
${toString setup}
|
|
while true
|
|
do
|
|
out=$(${cmd})
|
|
${toString process}
|
|
${
|
|
if view == null
|
|
then ""
|
|
else ''
|
|
echo "$out" | ${view}
|
|
''
|
|
}
|
|
${pkgs.inotify-tools}/bin/inotifywait -q -e modify -r $path
|
|
${toString stop}
|
|
done
|
|
''
|