commit 783c542abd223831a774b238ec64f62b801110f0
parent 04a5c83f3f07d9d990f9cc3acb3b19e013114c84
Author: Byron Torres <b@torresjrjr.com>
Date: Sun, 19 Dec 2021 16:38:20 +0000
add entr.ha
Diffstat:
A | .gitignore | | | 2 | ++ |
A | entr.ha | | | 65 | +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ |
2 files changed, 67 insertions(+), 0 deletions(-)
diff --git a/.gitignore b/.gitignore
@@ -0,0 +1,2 @@
+entr
+tmp/*
diff --git a/entr.ha b/entr.ha
@@ -0,0 +1,65 @@
+use fmt;
+use fs;
+use getopt;
+use io;
+use os;
+use os::exec;
+
+export fn main() void = {
+ const help: [_]getopt::help = [
+ "run abitrary commands when files change",
+ ('a', "respond to all events while the utility is running"),
+ ('c', "clear screen. specify twice to erase scrollback buffer"),
+ ('d', "track directories, exit when a new file is added"),
+ ('n', "non-interactive mode"),
+ ('p', "postpone first invocation until a file is modified"),
+ ('r', "reload a persistent child process"),
+ ('s', "evaluate the first argument interpreted by $SHELL"),
+ ('z', "exit after utility completes"),
+ "utility [argument [/_] ...] < filenames",
+ ];
+ const cmd = getopt::parse(os::args, help...);
+ defer getopt::finish(&cmd);
+
+ for (let i = 0z; i < len(cmd.opts); i += 1) {
+ const opt = cmd.opts[i];
+ switch (opt.0) {
+ case 'a' =>
+ abort("unimplemented option: -a");
+ case 'c' =>
+ abort("unimplemented option: -c");
+ case 'd' =>
+ abort("unimplemented option: -d");
+ case 'n' =>
+ abort("unimplemented option: -n");
+ case 'p' =>
+ abort("unimplemented option: -p");
+ case 'r' =>
+ abort("unimplemented option: -r");
+ case 's' =>
+ abort("unimplemented option: -s");
+ case 'z' =>
+ abort("unimplemented option: -z");
+ };
+ };
+
+ if (len(cmd.args) == 0) {
+ usage(help, void);
+ };
+
+ const args = if (len(cmd.args) > 1) cmd.args[1..] else []: []str;
+ const util = os::exec::cmd(cmd.args[0], args...)!;
+
+ const proc = os::exec::start(&util)!;
+ const stat = os::exec::wait(&proc);
+};
+
+@noreturn fn usage(help: []getopt::help, flag: (rune | void)) void = {
+ if (flag is rune) {
+ fmt::errorfln("{}: invalid option parameter for -{}",
+ os::args[0], flag: rune,
+ )!;
+ };
+ getopt::printusage(os::stderr, os::args[0], help);
+ os::exit(1);
+};