emeraldwalk / vscode-runonsave Goto Github PK
View Code? Open in Web Editor NEWVisual Studio Code extension to run commands whenever a file is saved.
License: Apache License 2.0
Visual Studio Code extension to run commands whenever a file is saved.
License: Apache License 2.0
Hi there,
I'm a big fan of this extension. It works really well and I use it every day. Thank you very much for building it.
There is one feature that I miss: A way to show a message to the user:
Is there a way to show a specific message to the user if something fails or any way to interact with the editor environment?
There is another "run on save" extension which offers a status bar message (https://github.com/pucelle/vscode-run-on-save) I did not try it yet but I think this might be a good feature extension for this run on save extension as well.
What do you think?
I'm working in a workspace with 2 main folders with similar structure. I want to use your extension on one of the folders for automatically syncronizing files on my development environment.
Structure looks like this:
mainfolder1/templates/
mainfolder2/templates/
my workspace settings look like this:
"emeraldwalk.runonsave": {
"commands": [
{
"match": "mainfolder1\\templates\\.*",
"cmd": "ROBOCOPY ${fileDirname} <development location> ${fileBasename} /is /it",
}
]
}
It doesnt work when i use this. It does work when i use:
""match": "templates\\.*",
but in both template folders (mainfolder2 too).
Is there any way to make this work while still working in a multi folder workspace?
Hi, I'm having an issue with grunt file, that is executed with the following instruction:
"emeraldwalk.runonsave": { "autoClearConsole": true, "commands": [ { "match": ".*", "isAsync": true, "cmd": "echo 'I run for all files.'" }, { "match": "\\.js$", "cmd": "echo 'I am a .js file ${file}.'" }, { "match": "\\.(js|css|scss)$", "cmd": "[[ ${file} = *'/js/'* || ${file} = *'/scss/'*|| ${file} = *'/static/'*]] && cd ${workspaceRoot} && grunt build" } ] }
I'm having this output:
I run for all files.
I am a .js file /home/aalbas/Documentos/sfcc_usa_dev08/xxxx/source/app_storefront_xxxx/cartridge/js/components/newsletterpopup.js.
*** cmd start: [[ /home/aalbas/Documentos/sfcc_usa_dev08/xxxx/source/app_storefront_xxxx/cartridge/js/components/newsletterpopup.js = '/js/' || /home/aalbas/Documentos/sfcc_usa_dev08/xxxx/source/app_storefront_xxxx/cartridge/js/components/newsletterpopup.js = '/scss/'|| /home/aalbas/Documentos/sfcc_usa_dev08/xxxxx/source/app_storefront_xxxx/cartridge/js/components/newsletterpopup.js = '/static/']] && cd / && grunt build
/bin/sh: 1: [[: not found
/bin/sh: 1: /home/aalbas/Documentos/sfcc_usa_dev08/xxxx/source/app_storefront_xxxx/cartridge/js/components/newsletterpopup.js: Permission denied
/bin/sh: 1: /home/aalbas/Documentos/sfcc_usa_dev08/xxxxx/source/app_storefront_xxxx/cartridge/js/components/newsletterpopup.js: Permission denied
Run on Save done.
First two commands, working well, third wrong.
Yes, Permission denied. I give chmod 777 to that file, give me a sintax error on that file. Something that's wrong because this file is comming from repo and working on production.
If I Execute grunt build on the terminal, and it is working perfectly. Not problems with permission.
I'm on ubuntu 18.04.
Visual Studio code: v1.32.3
runonsave: 0.0.18
What could be the cause? Thanks
Whenever we make the extension run we get error:
spawn C:\WINDOWS\system32\cmd.exe ENOENT
This is the correct path to cmd.exe.
Vscode's terminal window still works, executing cmd.exe from this extension seems to be the problem.
Reverting back to 0.0.18 is a temporary fix
Extension version: 0.1.0
Version: 1.36.1 (user setup)
Commit: 2213894ea0415ee8c85c5eea0d0ff81ecc191529
Date: 2019-07-08T22:59:35.033Z
Electron: 4.2.5
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Windows_NT x64 10.0.18362
Hi!
Great work so far. If I were to configure a task to format code on build, it will properly re-load the file I'm working on right in front of me. If I try to format "on-save" using this extension, it requires me to quickly ctrl-tab twice to reload the page.
Is this an extension issue or a problem with VS Code itself?
There is Open VSX Registry for VSCode extensions. It's an open-source alternative to the most popular VSCode marketplace. Some Linux distributions (at least Archlinux) package VSCode to use Open VSX registry by default. People using these distributions may have hard time figuring out why the extension can't be found (at least I couldn't find it there). I think the best solution is to support both registries and upload the extension to Open VSX. Could you please do that?
I'm using this plugin to train my algorithm where I wanted to immediately make input, righ upon file saving.
Sadly, STDIN is not redirected so I can type nothing on the output console.
vscode-runonsave/src/extension.ts
Lines 60 to 62 in 7bc6f1b
Only STDOUT and STDERR are piped and redirected.
Hello. would it be very difficult to launch visual studio commands? For example alt+`;alt+p. Thx!
If I add the statement console.log(process.argv)
to a JS file (file-changed.js), then have Run on Save execute that file, it prints the first two paths with escaped slashes, but the third path without any slashes at all. How can I fix this? The full output of the console.log statement is:
[
'C:\\Program Files\\nodejs\\node.exe',
'c:\\Users\\66851\\development\\projectb\\file-changed.js',
'c:Users66851developmentprojectbtest-file.js'
]
I have two different Node projects on my computer, both with Run on Save installed an in-use: projecta and projectb. In projecta, the output from Run on Save is as desired/expected. But in projectb, it is not.
Both projects have this configuration
Run on Save v0.2.0
I created a JS file in my project's root directory (file-changed.js
) and to it added only this statement:
console.log(process.argv)
"emeraldwalk.runonsave": {
"commands": [
{
"cmd": "node file-changed.js ${file}"
}
],
projecta has expected results
In projecta, if I save the file test-file.js, Run on Save executes filechanged.js, and prints this expected output to the console:
[
'C:\Program Files\nodejs\node.exe',
'c:\Users\66851\development\projecta\tasks\orbis-file-changed.js',
'c:\Users\66851\development\projecta\test-file.js'
]
Each path is separated with escaped slashes, as desired/expected.
projectb has unexpected results
In projectb, if I carry out the same test, the output is a little different:
[
'C:\\Program Files\\nodejs\\node.exe',
'c:\\Users\\66851\\development\\projectb\\file-changed.js',
'c:Users66851developmentprojectbtest-file.js'
]
The last path is missing slashes. Why is there this discrepancy between the two projects? This is causing issues for me because I need that path to be separated with slashes (or some other delimiter).
It would be very nice if we could customize the command to run before the formatter (for folks who has formatOnSave
enabled).
I have some runonsave commands defined that run windows command prompt commands such as rmdir and del.
If someone else is working on this project on a mac or on linux, I still want to be able to configure the *nix versions of those commands (ex: rm) so I can commit the vscode settings for the project and then it will "just work" if they have the plugin installed.
Thanks!
im trying to achieve this command
"cmd": "taskkill /IM notepad.exe && ./notepad.exe",
or
"cmd": "taskkill /IM notepad.exe; ./notepad.exe",
both aint working.
any suggestions?
Is it possible to get a glob matching rather than only regex?
{
"cmd": "blarblar",
"matchGlob": "myglob/**/*.ts"
}
or maybe
{
"cmd": "blarblar",
"match": "myglob/**/*.ts",
"globMatch": true,
}
??
Is there any option to run another extension command inside cmd
?
For example,
{
"match": "\\.dart",
"cmd": "dart-import.fix"
}
where dart-import.fix
is the command from another extension
I have a workspace that's a set of repos: a Meteor application and a variety of related npm modules. RunOnSave has been great for configuring babel to transpile whatever file I just saved, placing it based on the path by substitution of segment (basically, take the file path, and swap 'src' for 'lib').
For slightly more complicated scenarios (i.e., mocha testing), I'm unable to do the same because I need to access the repos' package.json, so I need to go into a node script to traverse up from the file. If captures in the match regex were made available as substitutions, it would simplify my task quite a bit and be generally pretty useful I think.
For example, If I could do this:
"match": "code/client/(.+)/src/.+\\.js$"
And then access it like this:
"cmd": "${workspacePath}/${1}/node_modules/.bin/mocha"
I could avoid dropping into a node script altogether.
I don't use typescript, but from looking at the code it looks like the following would be all that's needed:
At 139, change RegExp(pattern).test
to RegExp(pattern).exec
; this would return the match and still function as a boolean at 153
Inside the filter starting at 142, augment cfg
with the match/notMatch results:
cfg.matches = matchPattern.length === 0 || match(matchPattern) || [];
cfg.notMatches = match(negatePattern) || [];
return !cfg.notMatches && cfg.matches;
After replacing environment variables, replace matches with something like this around 181:
cfg.matches.forEach((match, ii) => {
cmdStr = cmdStr.replace(`\${${ii}}`, match);
});
Whenever I try to play a sound the extensions seems to get stuck.
It just keeps displaying Running on save commands...
and doesn't play any sound.
Here is an example of what I'm trying to do:
{
"match": ".*",
"cmd": "paplay '/home/sainoba/Music/knob.ogg",
},
paplay '/home/sainoba/Music/knob.ogg'
works fine if I run it in a terminal
Is there a way I can add a "pause" command? timeout
apparently doesn't work with runonsave.
I currently have some coffeescripts that compile. Unfortunately, since I can't use this extension (or can I?) to watch the "save"/overwrite of the compiled js, I'm trying to get it to run a command when I save a cofeescript, but wait 3 seconds to allow the stuff to compile to js. How can I achieve this?
shouldn't node be a dev dependency?
from the docs: https://code.visualstudio.com/api/get-started/extension-anatomy
"devDependencies": {
"@types/node": "^8.10.25",
"tslint": "^5.11.0",
"typescript": "^2.6.1",
"vscode": "^1.1.22"
}
Why only allow Workspace wide settings and not per folder? Now I have to create a new Workspace for every single PlatformIO project, which is a pain.
The "shell" configuration option had me confused becuase its hint text is:
Specify shell path to run commands (gets used in options arg passed to child_process.exec).
I read this to mean that it set the working directory in which the command is run. After reading the issue regarding shell, I realized it has to do with the actual shell the command is run in.
I was able to get the desired behavior for my particular use by writing the command as
cd ${workspaceRoot} && npm run-script browserify
.
The hint might be edited to
Specify the shell, including its path, in which to execute the command (gets used in options arg passed to child_process.exec).
I would like a formatting command to behave as VS Code, and not run if the file is autosaved after a delay, only when I manually save the file. It would be great to have such an option.
Currently, if I run the "File: Save All" , run-on-save fires off as many files are being saved. I would like it to only run once.
Consider this:
lessc C:/yada/somefile.less C:/yada/somefile.css
At the moment there is no way to get the filename without extension. It's trivial to add when hacking the JS file.
I have two variants of deploy scripts: deploy.sh and deploy.js.
They both use rsync over ssh to connect and deploy small apps to hosts.
The problem is that they both do when called from terminal, but if passed as a command to vscode-runonsave extension, they will both hang, and rsync task will remain indefinitely.
The same rsync script to another host works as intended when called manually or through vscode-runonsave extension.
If not glitch in the Matrix, what is? :)
Here are my settings:
// Place your settings in this file to overwrite the default settings { "saveAndRun": { "commands": [ { "match": ".go", "cmd": "echo
date ${srcFile} > ./context/.build" } ] } }
It rebuilds my Docker container on save. But RunOnSave will randomly append "echo date
${srcFile} > ./context/.build" to my open file.
I would like to see the output of the command it executed on save, is that possible?
The extension works only if the configuration is added in the users settings
not the workspace settings
, but the documentation says the configuration should be added in the workspace setting.
It should work with both the configuration but workspace settings should override the other.
It would be great if there was an option to switch to the 'Run On Save' output automatically if the command failed.
Or I even have a notification.
Thank you
Run on Save currently has ${relativeFile}
for the path relative to the workspace folder and ${fileDirname}
for the absolute directory of the file, but what I need is actually something like ${relativeDirname}
for the directory relative to the workspace folder.
I need this because I want to process some files and save the result in a dist/
subdirectory. I'm on Windows so my options for splitting the directory are very limited - I can strip off say the first 2 parts using the awkward for /F "tokens=2* delims=\" %A in ("${fileDirname}") do echo %B
, but I would like the command to not be dependent on knowing the nesting level of the workspace folder. Approaching this from the other direction - stripping off the file basename from ${relativeFile}
- doesn't appear to be possible on a single line.
Version: 1.39.2
Commit: 6ab598523be7a800d7f3eb4d92d7ab9a66069390
Date: 2019-10-16T10:47:27.951Z
Electron: 4.2.10
Chrome: 69.0.3497.128
Node.js: 10.11.0
V8: 6.9.427.31-electron.0
OS: Linux x64 5.3.5-1-default
My config file: The entire "emeraldwalk.runonsave"
section is greyed out. I do not know what that means.
{
"phpcbf.executablePath": "./vendor/bin/phpcbf",
"editor.minimap.enabled": false,
"zentabs.maximumOpenedTabs": 5,
"workbench.activityBar.visible": true,
"telemetry.enableCrashReporter": false,
"workbench.enableExperiments": false,
"workbench.settings.enableNaturalLanguageSearch": false,
"git.enableSmartCommit": true,
"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}.'"
}
]
}
}
Sometimes, I want to exec commands using different shell.
For example, I'm using nvm on zsh. And, child_process.exec()
uses /bin/sh
, which does not have nvm setup. This results in tsc
not found when I configure it to run on save.
Configuration option, "shell"
could be shell of choice:
{
"emeraldwalk.runonsave": {
"shell": "zsh",
"commands": [ ...]
}
}
I'm working with multi root workspaces and I am not able to get the folder root path in my command.
I would like to use something like "${workspaceFolder}" like is mentioned on the variable reference of vscode.
Can it be added or is there another way this can be achieved?
First, thanks for the extension, it's really helpful!
I was thinking it might be helpful to have an option to provide a sort of buffer between commands being run.
In my case, I've set a command rule to run my python unit tests every time it detects a python file change.
However, I also have auto-save enabled, so the moment I change anything in a file, VSCode saves it within a few hundred milliseconds, even if the changes was just adding some padding whitespace or something else inconsequential.
I'd love to be able to restrict this rule to only activate once every 5-10 seconds or something like that.
Currently, the CWD when running commands is always set to the VS Code installation directory (presumably since VS Code's plugin manager is the API used to invoke commands). If possible, it'd be extremely helpful to be able to specify a CWD to change to before executing a command. As it stands now, I'm blocked from automating some of my tasks when using this plugin because the CWD is in a write-protected area (program files) so my tasks can't write to disk.
This doesn't work (Pipe to file)
"emeraldwalk.runonsave": {
"commands": [
{
"match": ".sql",
"cmd": "cat ${file} | ~/sqlfmt --print-width 88 --tab-width 2 --use-spaces --no-simplify > ${file}"
}
]
}
This is a workaround:
"emeraldwalk.runonsave": {
"commands": [
{
"match": ".sql",
"cmd": "cat ${file} | ~/sqlfmt --print-width 88 --tab-width 2 --use-spaces --no-simplify > ${file}2; mv ${file}2 ${file}"
}
]
}
Any ideas?
${fileBasename} works fine
If my config is this
"emeraldwalk.runonsave": {
"commands": [
{
"match": ".ts$",
"cmd": "echo 'I am ${fileBasename}.'"
}
]
}
It echos in the footer of VS Code
***cmd start: echo 'I am filename.ts'
but if I change the cmd line to
"cmd": "echo 'I am ${file}.'"
Nothing happens on save.
I'm using VS Code 1.3 on Windows 7 64 bit
Hey,
is somehow possible to force not creating new terminal integrated window, instead split the existing window?
Thanks.
Hi, can this be configured to run internal key bindings or editor commands? Cheers
What a great plugin! This might help me migrate from Atom to VSCode.
How can I test for files in a certain directory? Or even better, files in a certain project.
I want to run an rsync command when files in one of my directories or its subdirectories are saved. I suppose I can do this with the match parameter, but I can't figure out how.
Hi all,
here's my config:
"emeraldwalk.runonsave": {
"commands": [
{
"match": "index.local.html",
"cmd": "patch --binary -i C:/Work/index.diff.txt -o C:/Work/index.html"
}
]
}
patch is the command-line tool coming with Git for Windows. The command is working fine when I run it from command line. But when I save index.local.html, I get index.html with zero size.
How to fix that?
Kindly post how this can be configured and tested using IDE screenshots.
Hi,
Trying to automate the sass compilation but I get this message :
Running on save commands...
*** cmd start: gulp --no-color sass
[14:59:42] Local gulp not found in C:\Program Files (x86)\Microsoft VS Code
[14:59:42] Try running: npm install gulp
gulp --no-color sass
works fine when done manually.
Gulp is installed globally
For VSCode to support that, it requires to expose new events. I created an issue in the VSCode github repo for that. Please upvote there!
it that possible ?
in docs
${workspaceFolder}: the path of the workspace folder of the saved file
on windows 10
if I put configs
{
"match": ".*\.scss$",
"command": "dir && cd ${workspaceFolder} && dir",
"runIn": "backend",
"runningStatusMessage": "Compiling ${fileBasename}",
"finishStatusMessage": "${fileBasename} compiled"
}
I get
Running "dir && cd \ && dir"
Volume in drive C has no label.
Volume Serial Number is 72ED-B5C7
Directory of C:\Users\[myUserName]\AppData\Local\Programs\Microsoft VS Code
....
start of vs code folder
and
${workspaceFolder} == "\"
how can I run command from workspace directory?
Issue Type: Bug
now the commands always end up with spawn C:\Windows\system32\cmd.exe ENOENT
Extension version: 0.1.0
VS Code version: Code - Insiders 1.37.0-insider (52b6e7c4f58466e5b67348fb67d359f6bc3bb7e8, 2019-07-18T05:35:22.001Z)
OS version: Windows_NT x64 6.1.7601
I have the following configuration set
"emeraldwalk.runonsave": {
"shell": "/usr/local/bin/bash",
"commands": [
{"match": ".*", "cmd": "echo ${file}"}
]
}
And I expect it to output something in the internal console, but nothing happens. Where is the output going? I'm using VSCode on a Mac
I needed some extra placeholder tokens to be able to copy files to secondary location, server, upon save:
Code changes: extension.ts line 169
cmdStr = cmdStr.replace(/\${relativeFile}/g, `${path.normalize(path.relative(vscode.workspace.rootPath, document.fileName))}`); cmdStr = cmdStr.replace(/\${workspaceRootDirname}/g, `${path.basename(vscode.workspace.rootPath)}`);
Example configuration:
"emeraldwalk.runonsave": { "commands": [ { "match": "\\.js$", "cmd": "if exist \"\\\\server\\Web\\${workspaceRootDirname}\\${relativeFile}\" copy /Y \"${file}\" \"\\\\server\\Web\\${workspaceRootDirname}\\${relativeFile}\"" } ] }
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.