英文:
Is there a way to store and select pre-configured bash commands with placeholders in Windows Terminal?
问题
我需要实现一个用于Windows终端的命令列表,它可以存储命令,以便选择预先配置的命令之一,并通过输入/点击将其输入到命令行提示符中。然后,我们可以在执行之前完成或填充占位符。
例如:
git commit -a -m "$"
我已经搜索过了,但没有找到最佳解决方案。
英文:
I need to implement a command list for windows terminal which store commands to select one of pre-configured commands to enter it in command line prompt by entering/clicking on it.
Then we can complete or fill placeholders before executing.
For example:
git commit -a -m "$"
I have searched for it but I have not found the best solution.
答案1
得分: 1
Not necessarily with the placeholders bit, but you can do something similar with the sendInput
action. For example, I have something like the following in my actions
in the settings.json
:
{
"command":
{
"action": "sendInput",
"input": "git add --all\r"
},
"name": "add all"
},
{
"command":
{
"action": "sendInput",
"input": "git commit -m \"\"\u001b[D"
},
"name": "commit..."
},
{
"command":
{
"action": "sendInput",
"input": "git fetch & git pull\r"
},
"name": "fetch&pull"
},
{
"command":
{
"action": "sendInput",
"input": "git merge origin/main\r"
},
"name": "merge main"
},
{
"command":
{
"action": "sendInput",
"input": "git log --graph --abbrev-commit --decorate --format=format:\"%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)\" --all\r"
},
"name": "graph"
},
Then you can just open the Command Palette with Ctrl+Shift+P, and fuzzy-find them in there.
(I even go a step further and nest these all under a git...
entry, so they're all grouped together.)
addenda:
- I'm tracking some improvements to this workflow in https://github.com/microsoft/terminal/issues/1595
- "placeholders" are tracked in: https://github.com/microsoft/terminal/issues/12927
英文:
Not necessarily with the placeholders bit, but you can do something similar with the sendInput
action. For example, I have something like the following in my actions
in the settings.json
:
{
"command":
{
"action": "sendInput",
"input": "git add --all\r"
},
"name": "add all"
},
{
"command":
{
"action": "sendInput",
"input": "git commit -m \"\"\u001b[D"
},
"name": "commit..."
},
{
"command":
{
"action": "sendInput",
"input": "git fetch & git pull\r"
},
"name": "fetch&pull"
},
{
"command":
{
"action": "sendInput",
"input": "git merge origin/main\r"
},
"name": "merge main"
},
{
"command":
{
"action": "sendInput",
"input": "git log --graph --abbrev-commit --decorate --format=format:\"%C(bold blue)%h%C(reset) - %C(bold green)(%ar)%C(reset) %C(white)%s%C(reset) %C(dim white)- %an%C(reset)%C(auto)%d%C(reset)\" --all\r"
},
"name": "graph"
},
Then you can just open the Command Palette with <kbd>Ctrl+Shift+P</kbd>, and fuzzy-find them in there.
(I even go a step further and nest these all under a git...
entry, so they're all grouped together.)
addenda:
- I'm tracking some improvements to this workflow in https://github.com/microsoft/terminal/issues/1595
- "placeholders" are tracked in:
https://github.com/microsoft/terminal/issues/12927
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论