有没有办法在Windows终端中存储和选择预配置的带占位符的bash命令?

huangapple go评论59阅读模式
英文:

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:

英文:

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:

huangapple
  • 本文由 发表于 2023年5月22日 15:58:31
  • 转载请务必保留本文链接:https://go.coder-hub.com/76304089.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定