【问题标题】:VSCode open terminal with directory does not appear to work带有目录的VSCode打开终端似乎不起作用
【发布时间】:2021-08-10 04:51:57
【问题描述】:

找到VSCode commandworkbench.action.terminal.newWithCwd

{
    "key": "cmd+shift+alt+h",
    "command": "workbench.action.terminal.newWithCwd",
    "args": {
      "cwd": "${fileDirname}"
    }
}

我无法让它工作。

我已将上面的 JSON 插入到 ~\Code\User\keybindings.json 文件中,但我如何真正让它执行?

【问题讨论】:

    标签: visual-studio-code terminal keyboard-shortcuts


    【解决方案1】:

    这用作键绑定,使用宏扩展 multi-command:

    {
      "key": "alt+k",       // whatever you want here
      "command": "extension.multiCommand.execute",
      "args": {
        "sequence": [
          {
            "command": "workbench.action.terminal.newWithProfile",
            "args": {
              "profileName": "Git Bash",
              "shouldForwardArgs": true,
            }
          }
          {
            "command": "workbench.action.terminal.sendSequence",
            "args": {
              "text": "cd '${fileDirname}'\u000D"
            }
          }
        ]
      },
      "when": "editorTextFocus"
    },
    

    我认为应该工作的是 settings.json 中的这个配置文件:

        "terminal.integrated.profiles.windows": {
          "PowerShell": {
            "source": "PowerShell",
            "icon": "terminal-powershell"
          },
          "Command Prompt": {
            "path": [
              "${env:windir}\\Sysnative\\cmd.exe",
              "${env:windir}\\System32\\cmd.exe"
            ],
            "args": [],
            "icon": "terminal-cmd"
          },
          "Git Bash": {
            "source": "Git Bash",
            "path": "C:\\Program Files\\Git\\git-bash.exe"
          },
          "Git Bash at fileDirname": {
            "source": "Git Bash",
            "path": "C:/Program Files/Git/git-bash.exe",
            "args": [
              "cd ${fileDirname}"       // variables are supported here according to the docs
            ]
          }
        },
    

    然后是这个关联的键绑定:

      {
        "key": "alt+k",
        "command": "workbench.action.terminal.newWithProfile",
        "args": {
          "profileName": "Git Bash at fileDirname",
          "shouldForwardArgs": true
        }
      },
    

    但这对我来说并不完全有效。它几乎可以工作,但它说不存在这样的文件。我在配置文件中看到了一些关于可变分辨率的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-22
      • 1970-01-01
      • 1970-01-01
      • 2022-06-17
      • 1970-01-01
      • 2019-08-02
      相关资源
      最近更新 更多