Command Snippet #8909

Closed
opened 2026-01-31 01:41:03 +00:00 by claunia · 9 comments
Owner

Originally created by @leopripos on GitHub (Jun 8, 2020).

Description of the new feature/enhancement

Create command snippets like IDE snippets. Users can type something and then press tab to complete automatically. This is basically very simmilar with directory / file auto complete.

This will be very useful for long commands.

Proposed technical implementation details (optional)

User can configure their snippet in settings.json, for ex:

{
  "snippets" : [
      {
        "snippet": "cd-project-x",
        "command": "cd  D:\Projects\Project-X\"
      },
      {
        "snippet": "dn-build-xxx",
        "command": "dotnet build D:\Projects\Project-X\ --param1 --param2 --param3"
      }
  ]
}
Originally created by @leopripos on GitHub (Jun 8, 2020). <!-- 🚨🚨🚨🚨🚨🚨🚨🚨🚨🚨 I ACKNOWLEDGE THE FOLLOWING BEFORE PROCEEDING: 1. If I delete this entire template and go my own path, the core team may close my issue without further explanation or engagement. 2. If I list multiple bugs/concerns in this one issue, the core team may close my issue without further explanation or engagement. 3. If I write an issue that has many duplicates, the core team may close my issue without further explanation or engagement (and without necessarily spending time to find the exact duplicate ID number). 4. If I leave the title incomplete when filing the issue, the core team may close my issue without further explanation or engagement. 5. If I file something completely blank in the body, the core team may close my issue without further explanation or engagement. All good? Then proceed! --> # Description of the new feature/enhancement Create command snippets like IDE snippets. Users can type something and then press tab to complete automatically. This is basically very simmilar with directory / file auto complete. This will be very useful for long commands. <!-- A clear and concise description of what the problem is that the new feature would solve. Describe why and how a user would use this new functionality (if applicable). --> # Proposed technical implementation details (optional) User can configure their snippet in settings.json, for ex: ``` { "snippets" : [ { "snippet": "cd-project-x", "command": "cd D:\Projects\Project-X\" }, { "snippet": "dn-build-xxx", "command": "dotnet build D:\Projects\Project-X\ --param1 --param2 --param3" } ] } ``` <!-- A clear and concise description of what you want to happen. -->
Author
Owner

@WSLUser commented on GitHub (Jun 9, 2020):

From CLI perspective, there is PSReadline and bash_completions, and other shell related autocompletion software. From settings perpective, there's already a json schema that's added that VSCode will intelligently recognize and provide suggestions for. It even recently added trailing comma support.

@WSLUser commented on GitHub (Jun 9, 2020): From CLI perspective, there is PSReadline and bash_completions, and other shell related autocompletion software. From settings perpective, there's already a json schema that's added that VSCode will intelligently recognize and provide suggestions for. It even recently added trailing comma support.
Author
Owner

@zadjii-msft commented on GitHub (Jun 9, 2020):

So, this is probably something that would be best served by whatever commandline app you're using. As @WSLUser mentioned, you can (probably) configure PSReadline to do something like this for powershell, bash_completions for bash, and I'm sure zsh, fish, etc all have their own variants.

If your preferred shell is cmd.exe, you're probably out of luck :/

<shameless self plug>
Though, my preferred shell is cmd, so I wrote #keep as a utility for doing exactly the two things you've called out above: going to a directory, and doing something in that directory:

image

The docs aren't great, and it hasn't been updated in a while (but that's because I don't really think it needs to be), but that might scratch your itch.

</shameless self plug>

@zadjii-msft commented on GitHub (Jun 9, 2020): So, this is probably something that would be best served by whatever commandline app you're using. As @WSLUser mentioned, you can (probably) configure PSReadline to do something like this for powershell, `bash_completions` for `bash`, and I'm sure `zsh`, `fish`, etc all have their own variants. If your preferred shell is `cmd.exe`, you're probably out of luck :/ \<shameless self plug> Though, my preferred shell is cmd, so I wrote [`#keep`](https://github.com/zadjii/keep) as a utility for doing exactly the two things you've called out above: `go`ing to a directory, and `do`ing something in that directory: ![image](https://user-images.githubusercontent.com/18356694/84173190-8c803f80-aa42-11ea-8c9b-90b0193b23d9.png) The docs aren't great, and it hasn't been updated in a while (but that's because I don't really think it needs to be), but that might scratch your itch. \</shameless self plug>
Author
Owner

@WSLUser commented on GitHub (Jun 9, 2020):

I believe Click was created for similar in cmd but the latest version is not stable and is abandoned. If you're not using in cmder though, it will be fine.

@WSLUser commented on GitHub (Jun 9, 2020): I believe Click was created for similar in cmd but the latest version is not stable and is abandoned. If you're not using in cmder though, it will be fine.
Author
Owner

@rmansnacks commented on GitHub (Jul 2, 2021):

I think there is important point that everyone is missing when telling us to rely on the shell completion functions. I want to be able to use snippets that are independent of the shell configuration. As an example, I often run awk '{ print $1 }' | while read... on server where I cannot create aliases or change any config, I would like to be able to type in 'a$1' for example and expand it to the predefined snippet. I'm often connecting to the systems where the completion is fully disabled and I run a lot of repetitive task that can't be scripted (terminal hijacking is always disabled). I'm really convinced this is a needed feature.

@rmansnacks commented on GitHub (Jul 2, 2021): I think there is important point that everyone is missing when telling us to rely on the shell completion functions. I want to be able to use snippets that are independent of the shell configuration. As an example, I often run awk '{ print $1 }' | while read... on server where I cannot create aliases or change any config, I would like to be able to type in 'a$1' for example and expand it to the predefined snippet. I'm often connecting to the systems where the completion is fully disabled and I run a lot of repetitive task that can't be scripted (terminal hijacking is always disabled). I'm really convinced this is a needed feature.
Author
Owner

@pem884 commented on GitHub (Nov 9, 2021):

I agree with @rmansnacks - have heard of one or two peers using "Ditto" clipboard manager for storing snippets in kind of a global way. I wouldn't be sure if there are any drawbacks to it, but wanted to comment in case anyone, like me, comes back here looking for "Windows Terminal Snippets". Hope this helps someone.

@pem884 commented on GitHub (Nov 9, 2021): I agree with @rmansnacks - have heard of one or two peers using "Ditto" clipboard manager for storing snippets in kind of a global way. I wouldn't be sure if there are any drawbacks to it, but wanted to comment in case anyone, like me, comes back here looking for "Windows Terminal Snippets". Hope this helps someone.
Author
Owner

@WSLUser commented on GitHub (Nov 9, 2021):

If an org has disabled shell completions, they don't understand security as well as they think. There's nothing to worry about with the basic completions or adding your own if permissions are kept to user and not administrator/root. Policy should be in place to not arbitrarily copy completions from the web and config management like ansible/puppet should enforce it . It's not hard at all.

@WSLUser commented on GitHub (Nov 9, 2021): If an org has disabled shell completions, they don't understand security as well as they think. There's nothing to worry about with the basic completions or adding your own if permissions are kept to user and not administrator/root. Policy should be in place to not arbitrarily copy completions from the web and config management like ansible/puppet should enforce it . It's not hard at all.
Author
Owner

@zadjii-msft commented on GitHub (Nov 9, 2021):

We're also more general-purpose tracking this in #1595, so go toss your 👍 on that thread ☺️

@zadjii-msft commented on GitHub (Nov 9, 2021): We're also more general-purpose tracking this in #1595, so go toss your 👍 on that thread ☺️
Author
Owner

@zadjii-msft commented on GitHub (Nov 9, 2021):

You could also theoretically create a command like:

{ "command": { "action": "sendInput", "input": "awk '{ print $1 }' | while read...\r" }, "keys":"ctrl+a", "name": "a$1" },

and then you could use the command palette to send that snippet really simply. So you'd just press Ctrl+Shift+P (to open the command palette),a,$,1,enter and it'd send that snippet to the terminal. Or leave out the \r to just input it on the prompt, but not submit. Kinda similar, and shell/backend agnostic.

@zadjii-msft commented on GitHub (Nov 9, 2021): You could also theoretically create a command like: ```jsonc { "command": { "action": "sendInput", "input": "awk '{ print $1 }' | while read...\r" }, "keys":"ctrl+a", "name": "a$1" }, ``` and then you could use the command palette to send that snippet really simply. So you'd just press <kbd>Ctrl+Shift+P</kbd> (to open the command palette),<kbd>a</kbd>,<kbd>$</kbd>,<kbd>1</kbd>,<kbd>enter</kbd> and it'd send that snippet to the terminal. Or leave out the `\r` to just input it on the prompt, but not submit. Kinda similar, and shell/backend agnostic.
Author
Owner

@pem884 commented on GitHub (Nov 11, 2021):

You could also theoretically create a command like:

{ "command": { "action": "sendInput", "input": "awk '{ print $1 }' | while read...\r" }, "keys":"ctrl+a", "name": "a$1" },

and then you could use the command palette to send that snippet really simply. So you'd just press Ctrl+Shift+P (to open the command palette),a,$,1,enter and it'd send that snippet to the terminal. Or leave out the \r to just input it on the prompt, but not submit. Kinda similar, and shell/backend agnostic.

Hey, that's brilliant - I'm excited to give it a try. Thanks so much, @zadjii-msft !!

@pem884 commented on GitHub (Nov 11, 2021): > > > You could also theoretically create a command like: > > ```js > { "command": { "action": "sendInput", "input": "awk '{ print $1 }' | while read...\r" }, "keys":"ctrl+a", "name": "a$1" }, > ``` > > and then you could use the command palette to send that snippet really simply. So you'd just press Ctrl+Shift+P (to open the command palette),a,$,1,enter and it'd send that snippet to the terminal. Or leave out the `\r` to just input it on the prompt, but not submit. Kinda similar, and shell/backend agnostic. Hey, that's brilliant - I'm excited to give it a try. Thanks so much, @zadjii-msft !!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#8909