~cdrozak/easywatch

A simple and easy to use tool to run command when files change

#7 Pass the file that triggered the event to the executed command

~cdrozak commented on easywatch todo

2 years ago

#7 Pass the file that triggered the event to the executed command

~ser commented on easywatch todo

2 years ago

#easywatch

A simple and easy to use tool to run command when files change.

Easywatch is meant as an alternative to inotifywait or entr, but has deliberately as little options as possible and does not require writing complicated scripts. It is based on Notify library.

#Usage

Run with the command specified after double hyphen -- to recursively watch all files in the current directory:

ewatch -- make

#-f/--format

You can specify one or more glob patterns to filter files with, using option -f or --format:

ewatch -f '**/*.mklx' -- make

#-p/--path

By default current directory is watched. To watch a different directories and/or single files pass an option -p or --path:

ewatch -p 'document.mklx' -p 'text/' -f '**/*.mklx' -- make

#EWATCH_FILE_PATH environment variable

Easywatch passes down to the command the EWATCH_FILE_PATH environment variable which contains a path to the changed file:

cat >hello_file.sh <<'EOF'
#!/usr/bin/env sh
echo "Hello $EWATCH_FILE_PATH!"
EOF
chmod +x hello_file.sh

ewatch -f '*.txt' -- ./hello_file.sh &

touch test.txt
# Hello <working directory>/./test.txt!

#Building

Easywatch can be built by calling cargo build --release. It will generate the easywatch binary in target/release directory. A symbolic link can then be created in some directory that is available in the $PATH. In my case it is ~/local/.bin:

ln -s "<easywatch repo>/target/release/easywatch" ~/local/.bin/ewatch