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",//whateveryouwantforakeybinding"command":"workbench.action.terminal.sendSequence","args":{"text":"echo '${selectedText}' | sort -\u000D"}}
This keybinding willecho
the selected text in the editor and pipe it to thesort
command, sorting the text alphabetically. The\u000D
represents theEnter
character to execute the command.
Feel free to customize the keybinding to suit your needs by replacing theecho '${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 simpleVSCode extension for this. See more details in the comment below.
Top comments(1)

- LocationMississauga, ON
- WorkSenior Software Engineer
- Joined
I just made aVSCode extension to allow user to execute shell commands with selected editor content as input. This will allow you to use the shell commands even more conveniently (no custom keybinding definition needed, commands can be edited).
This repo is still very basic (though useful), so you can add more functionalities if you want.
For further actions, you may consider blocking this person and/orreporting abuse