Le Vuong
Posted on April 11, 2024
Run shell script with editor content as input.
Looking to harness the capabilities of two powerhouse tools? Now you can execute shell scripts using the content directly from your VSCode editor.
Ref: stackoverflow
- Create a keyboard shortcut (Ctrl-Shift-P > Open keyboard shortcut (JSON) or openGlobalKeybindingsFile)
- In the keybindings.json file, add a new keyboard shortcut like below:
{
"key": "alt+t", // whatever you want for a keybinding
"command": "workbench.action.terminal.sendSequence",
"args": {
"text": "echo '${selectedText}' | sort - \u000D"
}
}
This keybinding will echo
the selected text in the editor and pipe it to the sort
command, sorting the text alphabetically. The \u000D
represents the Enter
character to execute the command.
Feel free to customize the keybinding to suit your needs by replacing the echo '${selectedText}' | sort -
with any shell command you prefer.
PS: It will even better if we can use a plugin that can accept commands as input. But I can't find one for now How about passing input to the bound key? Updated: I have created a simple VSCode extension for this. See more details in the comment below.
Posted on April 11, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.