,,,
(ಠ ಠ)
_( ^ )_
/ \/ \
// \ \
(/ / /
\______(_/
▐█▌█^║
▐█▌██║
▐█▌██║
▐█▌██║
▐█▌██║
_▐█▌██║
(___(__)
Witnessd is a pair of small template units for systemd, and a script for easy installation. It uses systemd.path unit to activate a systemd.service unit whenever a file or directory changes. It uses PathChanged=
option, so it is not activated on every write to the watched file, but it is activated when the file which was opened for writing gets closed.
Other possible options are described here. For example, PathModified=
is similar, but additionally it is activated also on simple writes to the watched file. Edit it in witessd@.path
if needed.
Download repository contents, examine the script and unit files, and run
./witnessd-add.sh path/to/watch command/to/run [additional arguments for the command]
witnessd-add.sh
copies the template units into users' systemd config dir ($HOME/.config/systemd/user/
by default), instantiates them with given arguments, and enables them.
Watched path must be absolute, but it may contain variables (they'll be expanded by the script), e.g. $HOME/somedir/
.
Command to run may contain "%" specifiers, e.g. %h/.local/bin/myscript.sh
.
This project was motivated by the lack of automated trimming of backups generated by Geany Save Actions plugin, as it doesn't have said functionality yet. While there are existing projects like entr, Watchman and fswatch, they seemed like an overkill for me, especially given that the necessary functions are already present in systemd.
This project doesn't have dependencies beside systemd (and bash for the script). There's no need for third-party software. On the downside, it is not cross-platform, and if fine-tuning is required, it may be necessary to dig into the vast systemd documentation.