Pass the file that triggered the event to the executed command

Could we let the command know which file changed? wendy does this by setting an environment variable ($WENDY_INODE), which is a nice solution that avoids argument positional issues.

Assigned to
2 years ago
2 years ago

~ser 2 years ago

I don't know Rust, so I don't know if this is acceptable; however, it appears to work:

diff --git a/src/main.rs b/src/main.rs
index 75b829b..f731ea6 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -64,6 +64,7 @@ fn main() {

                     // Spawn command
                     let status = Command::new(program)
+                        .env("EWATCH_INODE", path)
                         .expect("Failed to execute command");

~cdrozak 2 years ago

I think it's a nice solution. I would prefer a more precise variable name though, as inode is a name of a whole structure and we are only passing the file path. Maybe EWATCH_FILE_PATH?

In v2 I plan to add a find-like CLI, so it would be possible to do something like ewatch '*' -c echo File '{}' changed. I didn't have a lot of time recently, so that branch is pretty much stale for now, but hopefully I will have more time in the next week.

~ser 2 years ago

Awesome, thanks for accepting.

~cdrozak 2 years ago

I will leave this issue open, until I add it to the 2.0 branch

Register here or Log in to comment, or comment via email.