This extension allows configuring commands that get run whenever a file is saved in vscode.
NOTE: Commands only get run when saving an existing file. Creating new files, and Save as... don't trigger the commands.
- Configure multiple commands that run when a file is saved
- Regex pattern matching for files that trigger commands running
- Sync and async support
Add "emeraldwalk.runonsave" configuration to user or workspace settings.
- "shell" - (optional) shell path to be used with child_process.exec options that runs commands.
- "autoClearConsole" - (optional) clear VSCode output console every time commands run. Defaults to false.
- "commands" - array of commands that will be run whenever a file is saved.
- "match" - a regex for matching which files to run commands on
- "cmd" - command to run. Can include parameters that will be replaced at runtime (see Placeholder Tokens section below).
- "isAsync" (optional) - defaults to false. If true, next command will be run before this one finishes.
This sample configuration will run echo statements including the saved file path. In this sample, the first command is async, so the second command will get executed immediately even if first hasn't completed. Since the second isn't async, the third command won't execute until the second is complete.
"emeraldwalk.runonsave": {
"commands": [
{
"match": ".*",
"isAsync": true,
"cmd": "echo 'I run for all files.'"
},
{
"match": "\\.txt$",
"cmd": "echo 'I am a .txt file ${file}.'"
},
{
"match": "\\.js$",
"cmd": "echo 'I am a .js file ${file}.'"
},
{
"match": ".*",
"cmd": "echo 'I am ${env.USERNAME}.'"
}
]
}
The following commands are exposed in the command palette:
- On Save: Enable
- On Save: Disable
Commands support placeholders similar to tasks.json.
- ${workspaceRoot}: workspace root folder
- ${file}: path of saved file
- ${fileBasename}: saved file's basename
- ${fileDirname}: directory name of saved file
- ${fileExtname}: extension (including .) of saved file
- ${fileBasenameNoExt}: saved file's basename without extension
- ${cwd}: current working directory
- ${env.Name}