pucelle / vscode-run-on-save

Run configured shell commands when a file is saved in vscode, and output configured messages on status bar.
https://marketplace.visualstudio.com/items?itemName=pucelle.run-on-save
MIT License
50 stars 11 forks source link

Commands do not run from ${workspaceFolder} #11

Closed Lutier2017 closed 3 years ago

Lutier2017 commented 4 years ago

Hi, Normally I have all scripts to run in the ${workspaceFolder}. I noticed that any command ("runOnSave.commands": [ ]) is always run in Windows 7 from folder:

   C:\Users\{username}\AppData\Local\Programs\Microsoft VS Code

I mean, for the running script ${cwd} is as indicated above.

This is making me to invest additional effort to indicate the right folder of my scripts.

QUESTION: Is there a way to make any commands to run from ${workspaceFolder} instead?

I appreciate a reply.

This is my "settings.json" file

{
    "terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
    "jest.autoEnable": false,
    "runOnSave.statusMessageTimeout": 3000, 
    "runOnSave.shell": "C:\\Program Files\\Git\\bin\\bash.exe",
    "runOnSave.commands": [
        {
            "match": "lwAlias.js",
            "runIn": "backend",
            "command": "echo `pwd` ${cwd}",
            "runningStatusMessage": "copying file : ${fileBasename}",
            "finishStatusMessage": "File ${fileBasename} was copied to project folder ${workspaceFolder}"
        }
    ]
}

Please see system information below:

SYSTEM: Windows 7

VSCODE: Version: 1.48.2 (user setup) Commit: a0479759d6e9ea56afa657e454193f72aef85bd0 Date: 2020-08-25T10:13:11.295Z Electron: 7.3.2 Chrome: 78.0.3904.130 Node.js: 12.8.1 V8: 7.8.279.23-electron.0 OS: Windows_NT x64 6.1.7601

$ git --version git version 2.28.0.windows.1

$ bash --version GNU bash, version 4.4.23(1)-release (x86_64-pc-msys) Copyright (C) 2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html

pucelle commented 4 years ago

Yes, it's possible to config default working directory for all the runOnSave.commands or for each. The possible way is to add a runOnSave.defaultWorkingDirectory option or add a workingDirectory for each comment.

Give your suggestions, Thanks.

Lutier2017 commented 4 years ago

Hi, I think when you are developing a project, everything is in the project folder : ${workspaceFolder}. If you need any other stuff from another project, you copy/paste it in your project. Think about this:

From above description, I believe runOnSave.defaultWorkingDirectory is not required. IN FACT, "Run On Save" should execute any command BY DEFAULT in ${workspaceFolder}.

I believe, workingDirectory per command is the choice that "Run On Save" should include. Because, when you develop your project, you may need to develop stuff in other sub-project, or in a sub-folder of ${workspaceFolder}.

I appreciate your reply.

pucelle commented 4 years ago

Thanks for your explanation, I believe this is a good idea and will not make any trouble. I will work on it later.

pucelle commented 3 years ago

19 warned that it make some troubles when assigning default CWD as vscode working directory.

I added a new option workingDirectoryAsCWD, you may set it to true to make CWD to be vscode working directory.

pucelle commented 3 years ago

workingDirectoryAsCWD default value is true, nothing needs to change by default.