Coder Social home page Coder Social logo

danthe3rd / vscode-runonsave Goto Github PK

View Code? Open in Web Editor NEW

This project forked from emeraldwalk/vscode-runonsave

0.0 0.0 0.0 568 KB

Visual Studio Code extension to run commands whenever a file is saved.

License: Apache License 2.0

TypeScript 100.00%

vscode-runonsave's Introduction

Run On Save for Visual Studio Code

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.

Features

  • Configure multiple commands that run when a file is saved
  • Regex pattern matching for files that trigger commands running
  • Sync and async support

Configuration

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

    NOTE Since this is a Regex, and also in a JSON string backslashes have to be double escaped such as when targetting folders. e.g. "match": "some\\\\folder\\\\.*"

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

Sample Config

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}.'"
		}
	]
}

Commands

The following commands are exposed in the command palette:

  • On Save: Enable
  • On Save: Disable

Placeholder Tokens

Commands support placeholders similar to tasks.json.

  • ${workspaceRoot}: DEPRECATED use ${workspaceFolder} instead
  • ${workspaceFolder}: the path of the workspace folder of the saved file
  • ${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
  • ${relativeFile} - the current opened file relative to ${workspaceFolder}
  • ${cwd}: current working directory (this is the working directory that vscode is running in not the project directory)

Environment Variable Tokens

  • ${env.Name}

Links

License

Apache

vscode-runonsave's People

Contributors

bmingles avatar danthe3rd avatar artem-sidorenko avatar swiffer avatar saml avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.