Is there a way to create a keybinding to execute a shell command on a file? something like:
{
\"key\": \"ctrl+shift+e\",
\"command\": \"run\",
\"comm
with Marks answer here I could resolve my case that was run an android command with some shortcut. After that I decided to create an guide on my GitHub, hope that helps.
GitHub: LucasMMota
{
//... other configs you could have
"macros": {
"runCommandInTerminal": [
"editor.action.insertLineAfter", // go to new line below
{
"command": "type",
"args": {
"text": "adb shell input text \"RR\" " // exec cmd to reload android device (could be any else)
}
},
// select text typed above
{
"command": "cursorMove",
"args": {
"to": "wrappedLineStart",
"by": "wrappedLine",
"value": 1,
"select": true
}
},
"workbench.action.terminal.runSelectedText", //run command
"editor.action.clipboardCutAction", // remove cmd typed
//"editor.action.deleteLines", //couldn't use. When uncommented, command doesn't work
],
}
}
{
"key": "alt+s",
"command":"macros.runCommandInTerminal"
}
keybindings.json
:
{
"key": "cmd+s",
"command": "macros.saveContentAndIndent",
"when": "editorTextFocus && !editorReadonly"
},
User Settings
:
"macros": {
"saveContentAndIndent": [
"editor.action.formatDocument", // format
"workbench.action.files.save", // as I used Save shorcut, I add the save bind again.
],
//....
}