WatcherAndCommander
Description
WatcherAndCommander is an application for Windows which watches file system
directories for changes, and runs commands using cmd.exe
.
Setup
Each Commander is configured with a number of directories, a list of
commands, an optional working directory and an optional file filter. See
Setup_Commander.png for reference in the following.
Paths are monitoried recursively for creation, deletion, renames and
changes. Commands are separated by newlines, and are executed one by one
using cmd.exe /c
. Filters is a regular expression towards which the full
path of the changed file is matched. Working Directory determines from
which directory commands are run. If Working Directory is unset, commands
are run from the current working directory.
Expansions
Commands accepts several macro expansions:
${path} | Full path of the changed file |
${relpath} | Path of the changed file relative to the Working Directory |
${name} | Name of the changed file |
${directory} | Directory of the changed file |
For renamed files, there are also macro expansions for the old path of the file, i.e. the path before the rename operation:
${oldpath} | Full path of the original file |
${oldrelpath} | Path of the original file relative to the Working Directory |
${oldname} | Name of the original file |
${olddirectory} | Directory of the original file |
To facilitate certain operations on paths, the macros also have modifiers.
Macro modifiers take the form ${<modifier(s)>:<macro>}
. For example to
escape characters in the relative path such that it is suitable for a regular
expression, one can use the macro ${e:relpath}
. These are the macro
modifiers that are currently supported:
${e:<macro>} | Replace \ and . with \\ and \. respectively |
Disclaimer
This project was created to satsify a personal need to automatically update
tags
-files with ctags
, and to satisfy a curiosity for the C# language.
Therefore it is neither as feature complete as I would wish, nor as well
written.
I have tried to follow best practices for C# where I have found them, but I come from a C++ background and this probably shows in the code. Feel free to fork and improve the code, and educate me where I have gone wrong.
There are probably a lot of corner cases that I have missed, and exceptions I should have caught. If you find a problem, write an issue report or submit a pull request.
TODO
- Add an option to disable recursive monitoring of directories
- Add more macro modifiers:
- Modifier to enclose macro in quotes
- Modifier to escape whitespaces
- Improve logging: add better support for viewing stdout and stderr from commands.
- Add a notification to the Commander list to indicate when a file has been changed. (I.e. temporarily change the colour of the commander name.)
- Improve documentation
- Do some proper testing