Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add a custom command in Visual Studio Code Command Palette

Is it possible out of the box or using extensions to add a custom command in the Command Palette in Visual Studio Code like "External Tools" as in the IDE from JetBrains or in Visual Studio?

I would like to be able to run custom bash/cmd command directly from the Command Palette.

like image 881
Victor S. Avatar asked May 22 '18 16:05

Victor S.


2 Answers

You can either use VS Code built-in functionality using shortcuts. Just add to keybindings.json:

{
  "key": "cmd+shift+R",
  "command": "workbench.action.terminal.sendSequence",
  "args": {
    "text": "clear; rails server\u000D"
  }
},

Or you can take a look at this extension: Command Runner

like image 117
Flavio Wuensche Avatar answered Sep 16 '22 14:09

Flavio Wuensche


https://marketplace.visualstudio.com/items?itemName=usernamehw.commands

This extension can run it from custom Quick Pick (like command palette, but shows only your items). Command id is commands.openAsQuickPick


There's no api to seamlessly add commands to Command Palette #1422, but it's possible to modify package.json what that extension does when this setting is enabled:

"commands.populateCommandPalette": true,

With this setting it will not update Command Palette until the editor is reloaded. It might be an ok experience if you don't do that very often.

like image 24
Alex Avatar answered Sep 20 '22 14:09

Alex