GorvGoyl / Shortcut-Menu-Bar-VSCode-Extension

Add handy buttons like beautify, show opened files, save, toggle terminal, etc to the editor menu bar in VSCode. You can also create your own buttons with custom commands. VSCode Marketplace link: https://marketplace.visualstudio.com/items?itemName=jerrygoyal.shortcut-menu-bar
https://marketplace.visualstudio.com/items?itemName=jerrygoyal.shortcut-menu-bar
GNU General Public License v3.0
221 stars 44 forks source link

How to run code in terminal with "custom button"? #67

Closed ttodua closed 2 years ago

ttodua commented 2 years ago

Wanted i.e. while clicking on custom button, to run npm install command in terminal, but couldnt figure it out.

yuraware commented 2 years ago

You need to create a task in the VSCode https://code.visualstudio.com/docs/editor/tasks.

tasks json — flutter 2021-11-28 20-45-23

E.g.

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Run tests",
      "type": "shell",
      "command": "./scripts/test.sh",
      "windows": {
        "command": ".\\scripts\\test.cmd"
      },
      "group": "test",
      "presentation": {
        "reveal": "always",
        "panel": "new"
      }
    }
  ]
}

Then go to the extension settings and set the next to the custom button command workbench.action.tasks.runTask| flutter: Run tests where Run tests is the task label.

ttodua commented 2 years ago

i've tried and made it work, however, isn't it possible to just run any sample command directly in the open terminal, without starting the task (being placed in toolbar with loading icon aside : https://i.imgur.com/klEqRww.png ) ?

GorvGoyl commented 2 years ago

closing due to no activity

ttodua commented 2 years ago

well, no activity because I've not got an answer. thanks anyway

GorvGoyl commented 2 years ago

@ttodua It's tricky but I think it's achievable by using multi-command extension and the power of workbench.action.terminal.sendSequence. You can create a custom command which would send the command (like npm run dev) to the terminal and execute it. You can mention this custom command in SMB.

https://stackoverflow.com/questions/52786022/shortcut-for-running-terminal-command-in-vs-code https://code.visualstudio.com/docs/editor/integrated-terminal#_send-text-from-a-keybinding

ttodua commented 2 years ago

Many thanks for answer. that makes the trick.