Bind a keypress to a shell command that uses the current file in visual studio code

后端 未结 3 860
悲哀的现实
悲哀的现实 2021-01-25 07:16

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         


        
3条回答
  •  囚心锁ツ
    2021-01-25 07:53

    Update: VS Code now provides variables for integrated terminal commands. https://code.visualstudio.com/updates/v1_32#_variable-support-in-send-sequence-command

    If you'd like to do more powerful tasks such as running them in the background (instead of just sending text to the current terminal) get the Command Runner or macro-commander extension

    I created an extension macro-commander to solve this with a non-hacky solution. It is an improved version of the macros extension that runs the commands in order (synchronously) and lets you inject the filepath/folderpath into the command. Commands can be run in the user's VS Code terminal or a hidden background terminal.

    UPDATE: As of today (months later) I realized, much to my dismay, there was an existing extension that can probably do what you (and I) wanted. It is Command Runner written by edonet. If I had known about it I probably would've never made my extension.

    Command Runner doesn't have as much generic possibilities (multiple commands, user input, or javascript) but it has a better UX and is probably the extension you (the reader) should try first. However, if Command Runner can't do what you're looking for, then macro-commander probably can, albeit with less elegance.

    Whenever I decide to do a full update to macro-commander I'll talk with edonet and see if we can combine/add the functionality into his extension, in which case I'll update the macro-commander README to redirect to his/her extension.

提交回复
热议问题