Extension to run external commands when files are saved or changed.
This extension allows you to configure watchers in your settings.json and expand macros (like $FilePath$, $FileDir$) to execute dynamic commands.
Features
- Trigger commands automatically on file save
- Filter triggered files using simple glob patterns
- Replace macros like
$FilePath$and$FileName$ - View output in a dedicated Output Console
- Configure environments and working directories dynamically
Configuration
In your settings.json (Workspace or User settings), add the watchfile.watchers array:
"watchfile.watchers": [
{
"name": "WatchLuaFileSave",
"enabled": true,
"fileNamePattern": "**/*.lua.txt",
"program": "${workspaceRoot}\\tools\\idea_tools\\hot_reload_lua_file.bat",
"arguments": [
"lua_file_path",
"$FilePath$",
"event_name",
"reload_lua_file"
],
"workingDirectory": "$FileDir$",
"autoSaveTrigger": true,
"triggerOnExternalChanges": true,
"showConsole": "always"
}
]
Properties
name: Watcher name (required).enabled: Disable watcher without removing it (defaulttrue).fileNamePattern: A basic glob pattern to filter triggering files, like*.jsor**/*.ts(default**/*).program: The executable program to run (required).arguments: Array of arguments for the program. Macros can be used here.workingDirectory: Directory to run the command in. Defaults to$FileDir$.environmentVariables: Key-value object of env variables. Values can use macros.autoSaveTrigger: Trigger watcher on save (defaulttrue).showConsole: When to reveal the Output Console.always,onError,never(defaultonError).