Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Le Vuong
Le Vuong

Posted on • Edited on

     

VSCode Tips

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"}}
Enter fullscreen modeExit fullscreen mode

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)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
patfinder profile image
Le Vuong
• Learn everyday new useful technologies• Learn anything that broadens my understanding of the world.
  • Location
    Mississauga, ON
  • Work
    Senior 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.

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

• Learn everyday new useful technologies• Learn anything that broadens my understanding of the world.
  • Location
    Mississauga, ON
  • Work
    Senior Software Engineer
  • Joined

More fromLe Vuong

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp