Skip to content
Visual Studio Code extension to run commands whenever a file is saved https://marketplace.visualstudio.com/items?itemName=wk-j.save-and-run
Branch: master
Clone or download
Pull request Compare This branch is 7 commits ahead, 27 commits behind wk-j:master.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode Update engine Jun 24, 2017
images Update README Jul 11, 2017
src bugfixes Aug 25, 2017
test Initial Commit Nov 27, 2015
.gitignore bugfixes Aug 25, 2017
.vscodeignore Fixed wk-j#4 Jun 27, 2017
LICENSE Initial commit Nov 27, 2015
README.md Update README.md Aug 25, 2017
_config.yml Set theme jekyll-theme-slate Mar 14, 2017
build.cake
build.sh Create build script ಠ_ಥ Oct 24, 2016
package-lock.json Update engine Jun 24, 2017
package.json bugfixes Aug 25, 2017
tsconfig.json Update engine Jun 24, 2017

README.md

Run saved file in Terminal or a VS Code Extension command

Fork from vscode-save-and-run

Extends the original extension to execute VS Code extension commands or terminal-commands

Features

  • Configure multiple commands (terminal or command from VS Code extension) that run when a file is saved
  • Regex pattern matching for files that trigger commands running

Note

  • Commands only get run when saving an existing file. Creating new files, and Save as... don't trigger the commands.

  • For Ubuntu user, you have to install xclip

    sudo apt-get install xclip
    

Configuration

Add "saveAndRunExt" configuration to user or workspace settings.

  • "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).

Sample Config

"saveAndRunExt": {
	"commands": [
		{
			"match": ".*",
			"isShellCommand" : false,
			"cmd": "myExtension.amazingCommand"
		},
		{
			"match": "\\.txt$",
			"cmd": "echo 'Executed in the terminal: I am a .txt file ${file}.'"
		}
	]
}

Commands

The following commands are exposed in the command palette

  • Save and Run Ext : Enable
  • Save and Run Ext : Disable

Placeholder Tokens

Commands support placeholders similar to tasks.json.

  • ${workspaceRoot}: workspace root folder
  • ${file}: path of saved file
  • ${relativeFile}: relative 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

Environment Variable Tokens

  • ${env.Name}

License

Apache

You can’t perform that action at this time.