【问题标题】:Automatically Execute a command when opening a new Integrated Terminal in VSCode IDE在 VSCode IDE 中打开新的集成终端时自动执行命令
【发布时间】:2017-07-08 09:46:58
【问题描述】:

VSCode IDE 可以做到这一点吗? 打开新的集成终端时自动执行命令,例如运行批处理文件或powershell脚本?

【问题讨论】:

    标签: visual-studio-code vscode-settings


    【解决方案1】:

    是的,您可以使用"terminal.integrated.shellArgs" 设置将参数传递给shell。例如,以下将在打开新终端实例时打印Hello World

    "terminal.integrated.shellArgs.windows": [
        "-NoExit", "-Command", "Write-Host Hello World"
    ]
    

    【讨论】:

    • 这在当前版本的 VSCode 上对我不起作用
    • 嗯...这在 1.23.1 中仍然可以正常工作,假设 a)您在 Windows 上 b)您没有将 terminal.integrated.shell.windows 更改为默认值(PowerShell)以外的其他值.
    • @Urasquirrel 它必须工作,但这适用于 win8 和 10,因为它们使用 powershell,在 win 7 vscode 中使用 cmd,所以使用 cmd 命令。阅读它here
    【解决方案2】:

    以前的答案已被弃用,尽管它仍然可以工作,但会发出警告。在 VS Code 中执行此操作的新方法是将此部分添加到您的 settings.json。在这里,我将我的 PowerShell 配置为自动导入一个模块 posh-git,该模块可以美化我的 git 命令提示符。 :)

        "terminal.integrated.profiles.windows": {
    
        "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell",
            "args": [
                "-NoExit", "-Command", "Import-Module posh-git"
            ]
        },
        "Command Prompt": {
            "path": [
                "${env:windir}\\Sysnative\\cmd.exe",
                "${env:windir}\\System32\\cmd.exe"
            ],
            "args": [],
            "icon": "terminal-cmd"
        },
        "Git Bash": {
            "source": "Git Bash"
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2018-03-09
      • 2020-05-14
      • 2015-11-04
      • 1970-01-01
      • 2022-06-17
      • 1970-01-01
      • 2020-06-18
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多