Code Monkey home page Code Monkey logo

vscode-save-and-run's Introduction

Run saved file in Terminal

Version Installs

Fork from vscode-runonsave

Simplify original extension by pass command into Terminal directly without spawn process, so we don't lose output colors.

Features

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

Configuration

Add "saveAndRun" 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).
  • "useShortcut" - Execute file with shortcut key Command + Shift + R
  • "silent" - Don't show terminal after save. Defaults to false

Sample Config

"saveAndRun": {
  "commands": [
    {
      "match": ".*",
      "cmd": "echo 'I run for all files.'",
      "useShortcut": false,
      "silent": false
    },
    {
      "match": "\\.txt$",
      "cmd": "echo 'I am a .txt file ${file}.'",
      "useShortcut": false,
      "silent": false
    }
  ]
}

Commands

The following commands are exposed in the command palette

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

Placeholder Tokens

Commands support placeholders similar to tasks.json.

  • ${workspaceRoot} - workspace root folder
  • ${workspaceFolder} - the path of the folder opened in VS Code
  • ${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

vscode-save-and-run's People

Contributors

artem-sidorenko avatar bmingles avatar code-factor avatar craigbrett17 avatar hsiaosiyuan0 avatar imgbotapp avatar saml avatar victorporof avatar wk-j avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

vscode-save-and-run's Issues

Doesn't work at all in the January update

This plugin isn't working at all in the January update, version 1.31.1. I get the message that commands are being run in the Output window but no command actually runs and no further output is generated.
Test commands provided in the doc also fail.

Save and Run 0.0.21
VSCode 1.31.1
Win 7 Pro

Run on Save does still work, for the record.

Thanks.

Improvement: add parameter to enter file directory before running the command

Hi,

I believe it would be useful to have a command property with boolean values (like silent) that would force to enter the directory of the file (i.e. doing a "chdir") before running the command specified in cmd.

That would be useful, especially for large projects.

A possible name for this parameter could be chdir.

Disable Run and Save not working

I'm on VS Code stable, latest version, it's not working when I tried to disable it. It still run the command, any Ideas? Thanks

Event not fired

Hi there, I have added the following to my settings.json file;

"saveAndRun": {
        "commands": [
            {
                "match": "snapcraft.yaml$",
                "cmd": "echo 'I am a .yaml file ${file}.'"
            }
        ]
    }

And I have a file called 'snapcraft.yaml' open, and when I save, there is no output at all.
Am I missing something?

[DepShield] (CVSS 7.4) Vulnerability due to usage of lodash.isequal:4.5.0

Vulnerabilities

DepShield reports that this application's usage of lodash.isequal:4.5.0 results in the following vulnerability(s):


Occurrences

lodash.isequal:4.5.0 is a transitive dependency introduced by the following direct dependency(s):

vscode:1.1.18
        └─ gulp-symdest:1.1.0
              └─ vinyl-fs:2.4.4
                    └─ lodash.isequal:4.5.0

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

CTRL C?

Is it possible to cancel the current program and then rerun it with Save and Run?

how to get it to catch a git undo action?

it works great when editing files. but, whenever using the git undo feature to undo changes in a file with pending changes, it doesn't seem to catch that complete undo change for the file.
is there a way to get it to catch a git undo action?
thanks,

Save&Run erase the clipboard with "cmd" content

I use Save&Run to execute gulp whenever I save a .scss file. The issue is that when it executes the command, my clipboard content is replaced with "gulp" (which is the only content of the "cmd" attribute).

My config (workspace):

"saveAndRun": {
        "shell": "${workspaceRoot}",
        "commands": [
            {
                "match": ".scss",
                "cmd": "gulp",
                "isAsync": true
            }
        ]
    }

Focus on terminal window after running

After running the program, either by saving the file or by the use of shortcut ( settings.json -> "useShortcut" : true ) mouse pointer is not focusing on the terminal.

Each save opens a new terminal

Works great but for each save there is a new terminal window created which is not ideal. A typical user will edit save regularly and will have to remember to close all those terminal windows. It also gets confusing for them to keep track of them all.

I suspect this is by design so it is possible to run multiple commands in parallell. Would it be possible to have an option to kill the previous terminal when again saving and triggering output for the same command?

[DepShield] (CVSS 7.5) Vulnerability due to usage of tar:2.2.1

Vulnerabilities

DepShield reports that this application's usage of tar:2.2.1 results in the following vulnerability(s):


Occurrences

tar:2.2.1 is a transitive dependency introduced by the following direct dependency(s):

vscode:1.1.18
        └─ gulp-untar:0.0.7
              └─ tar:2.2.1

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

How can i add the config for each project in my workspace

Hello,

i have a workspace with some projects(folders) in it.

Is it possible to add a config for every project instead of the whole workspace?

When i try to add the config to the folder settings tab, i get the message that it isnt allowed in the workspace view.

When i add the config to workspace settings it wont start, when i press save.

Placeholder tokens do not work on Windows

E.g. use the ${workspaceFolder} placeholder which will lead to /C:/some/folder instead of C:/some/folder. Notice the extra slash.
Makes this plugin unusable on Windows :(

relativeFile not working on Windows

the variable ${relativeFile} is not working for me on Windows 10.

"cmd": "echo '${relativeFile}'" results in this string: '.d:\Development\project\file'.
Had a quick look in the code and it appears that rootFolder.uri.path is a path with forward-slashes while document.fileName is a path with backslashes. This results in the line document.fileName.replace(root, "") not actually replacing anything.

I noticed that rootFolder.uri.fsPath has the correct slashed. But since I'm on Windows I don't know how changing this would affect the other platforms.

Not sure how actively this is looked upon. But I just thought I should report the issue

[DepShield] (CVSS 9.8) Vulnerability due to usage of node.extend:1.1.6

Vulnerabilities

DepShield reports that this application's usage of node.extend:1.1.6 results in the following vulnerability(s):


Occurrences

node.extend:1.1.6 is a transitive dependency introduced by the following direct dependency(s):

vscode:1.1.18
        └─ gulp-remote-src-vscode:0.5.0
              └─ node.extend:1.1.6

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

ERR color: #f33 Cannot read property 'forEach' of undefined: TypeError: Cannot read property 'forEach' of undefined

Delayed file savings, cannot figure out what's wrong. This shows up in the log:

[15193:0722/125659.939274:INFO:CONSOLE(1670)] "%c  ERR color: #f33 Cannot read property 'forEach' of undefined: TypeError: Cannot read property 'forEach' of undefined
    at RunOnSaveExtension.runAllInTerminal (/Users/rolle/Projects/vscode-settings/.vscode/extensions/wk-j.save-and-run-0.0.21/out/src/runner.js:18:18)
    at RunOnSaveExtension.runCommands (/Users/rolle/Projects/vscode-settings/.vscode/extensions/wk-j.save-and-run-0.0.21/out/src/runner.js:111:14)
    at /Users/rolle/Projects/vscode-settings/.vscode/extensions/wk-j.save-and-run-0.0.21/out/src/extension.js:30:19
    at l.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:45:801)
    at t.ExtHostDocuments.$acceptModelSaved (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:651:298)
    at m._doInvokeHandler (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:801:683)
    at m._invokeHandler (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:801:375)
    at m._receiveRequest (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:800:14)
    at m._receiveOneMessage (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:798:832)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:797:34
    at l.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:45:801)
    at v.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:235:849)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:975:744
    at l.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:45:801)
    at v.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:235:849)
    at t.PersistentProtocol._receiveMessage (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:240:276)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:237:357
    at l.fire (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:45:801)
    at p.acceptChunk (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:233:393)
    at /Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:232:753
    at Socket.t (/Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/services/extensions/node/extensionHostProcess.js:241:826)
    at Socket.emit (events.js:203:13)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:276:11)
    at Socket.Readable.push (_stream_readable.js:210:10)
    at Pipe.onStreamRead (internal/stream_base_commons.js:166:17)", source: file:///Applications/Visual Studio Code.app/Contents/Resources/app/out/vs/workbench/workbench.desktop.main.js (1670)

[DepShield] (CVSS 7.5) Vulnerability due to usage of fstream:1.0.11

Vulnerabilities

DepShield reports that this application's usage of fstream:1.0.11 results in the following vulnerability(s):


Occurrences

fstream:1.0.11 is a transitive dependency introduced by the following direct dependency(s):

vscode:1.1.18
        └─ gulp-untar:0.0.7
              └─ tar:2.2.1
                    └─ fstream:1.0.11

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

"match" not subfolder

Need to NOT match filename contained in subfolders...
Match index.html but not /subfolder/index.html
This Regex does not work: ^[^\\]*\\index\.html$

Is there a way to do this? What 'flavor' of regex is supported?
Thanks.

where does the output go? echo statement never seen??

I may be missing something basic... but I cannot see that the echo statements in the "Sample Config" posted, go anywhere.
I don't see them in the Output for Save and Run.
I don't see them in the Terminal.
I don't see them in the status bar.

All I can ever find is "Running on save commands..." (in status bar and in Output)

What am I missing?

Hide command being executed

I know I can redirect command's output to /dev/null, but is there a way to hide command itself i.e. the command completely silent?

Does not work for .ipynb files

I have both Python and Jupyter extensions installed.

If I rename my ipynb file to have the extension ipynbb and change the "save and run" settings accordingly then the command gets triggered as expected. But if I change the file extension back to ipynb then nothing happens.

[DepShield] (CVSS 7.5) Vulnerability due to usage of mocha:5.2.0

Vulnerabilities

DepShield reports that this application's usage of mocha:5.2.0 results in the following vulnerability(s):

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

[DepShield] (CVSS 7.5) Vulnerability due to usage of mocha:4.1.0

Vulnerabilities

DepShield reports that this application's usage of mocha:4.1.0 results in the following vulnerability(s):


Occurrences

mocha:4.1.0 is a transitive dependency introduced by the following direct dependency(s):

vscode:1.1.18
        └─ mocha:4.1.0

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

Stop working

Stop working and just paste the copied content that are in the transfer area to the command line.
There is some way to check if some other extension are affecting it?

Default output in terminal.

I have a super simple config just to test...

"saveAndRun": {
        "commands":[ 
            {
            "match": "snapcraft.yaml$",
            "cmd": "echo 'hello there!'"
            }            
        ]
    }

When I save that file, I get the following output in the terminal:

$ {
>             "match": "\\.txt$",
>             "cmd": "echo 'I am a .txt file ${file}.'"
>         }

I then have to ctrl-c in the terminal to get the prompt.

So:

  1. While it is matching, why is it outputting a portion of your sample config?
  2. As you can see, my config is supposed to just echo a simple string?

Then I tried with this config:

"saveAndRun": {
        "commands":[ 
            {
            "match": "snapcraft.yaml$",
            "cmd": "ls -al ~"
            }            
        ]
    }

And the output is the same default string broken up between multiple terminal lines.echo "echo 'hello there!

Then I edited it back the original and now I am getting:

dkrysak@awslin01:~/Documents/Projects$ "saveAndRun": {
saveAndRun:: command not found
dkrysak@awslin01:~/Documents/Projects$         "commands":[
commands:[: command not found
dkrysak@awslin01:~/Documents/Projects$             {
>             "match": "snapcraft.yaml$",
>             "cmd": "ls -al ~"
>             }
No command 'match:' found, did you mean:
 Command 'match' from package 'mailavenger' (universe)
match:: command not found
cmd:: command not found
dkrysak@awslin01:~/Documents/Projects$         ]
]: command not found
dkrysak@awslin01:~/Documents/Projects$     }

It seems to be super inconsistent.

Paths in Windows got a "\" which might lead to wrong interpretations

Hi, great program!

I use VS Code on Windows and trouble using paths (relative or absolute).

I have the following configuration

            {
                "match": "\\.adoc$",
                "cmd": "asciidoctor ${file}",
                "useShortcut": false,
                "silent": false
            }

And this leads to following output in Terminal

$ asciidoctor c:\dir1\dir2/myfile.adoc
asciidoctor: FAILED: input file c:dir1dir2/myfile.adoc is missing

Any suggestion on how to do?

Runs odd command from last line of file

I have this in my settings.json:

// Place your settings in this file to overwrite default and user settings.
{
    "saveAndRun": {
        "commands": [
            {
                "match": "\\.tsx?$",
                "cmd": "tsc ${file}"
            },
            {
                "match": "museum_theme.less$",
                "cmd": "lessc --verbose --source-map museum_theme.less museum_theme.css"
            },
            {
                "match": "\\.less$",
                "cmd": "lessc --verbose --source-map --glob style.less style.css"
            }
        ]
    }
}

If I edit the "museum_theme.less" which contains just this:


// Hello

Notice that // Hello is last line of the file

It does something odd in the console:

PS C:\Source\...> lessc --verbose --source-map museum_theme.less museum_theme.css
>>
lessc: wrote ...\museum_theme.css
lessc: wrote ...\museum_theme.css.map
PS C:\Source\...> // Hello wtf?
>>
// : The term '//' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ // Hello wtf?
+ ~~
    + CategoryInfo          : ObjectNotFound: (//:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

It tries to run the last line of the file in museum_theme.less, the problem must be in the extension since no such thing happens with running lessc --verbose --source-map museum_theme.less museum_theme.css on it's own.

Format for "match" parameter

Hello, I'm trying to make a command that runs on all .js files in a certain folder (*/source/js/). I can't figure out the match format for the life of me. Do you have any advice or resources to point me to?

Support for Multi-root Workspaces

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?

[DepShield] (CVSS 6.1) Vulnerability due to usage of url-parse:1.4.1

Vulnerabilities

DepShield reports that this application's usage of url-parse:1.4.1 results in the following vulnerability(s):


Occurrences

url-parse:1.4.1 is a transitive dependency introduced by the following direct dependency(s):

vscode:1.1.18
        └─ url-parse:1.4.1

This is an automated GitHub Issue created by Sonatype DepShield. Details on managing GitHub Apps, including DepShield, are available for personal and organization accounts. Please submit questions or feedback about DepShield to the Sonatype DepShield Community.

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.