rework watch command

This commit is contained in:
Tristan 2024-01-03 06:47:16 +00:00
parent 4f6c21ec77
commit 3faf0e6354
6 changed files with 32 additions and 61 deletions

View file

@ -3,4 +3,5 @@
it = import ./it.nix;
test = import ./test.nix;
watch = import ./watch.nix pkgs;
filters = import ./filters.nix;
}

View file

@ -9,6 +9,7 @@ pkgs: files: let
in (pkgs.writeShellScriptBin "test" ''
t=$1
case "$t" in
"file") echo '${resFile}' ;;
"raw") cat '${resFile}' ;;
"json") jq '.' '${resFile}' ;;
"nix") ${extractNix} | ${pkgs.alejandra}/bin/alejandra -q ;;

View file

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