【问题标题】:Vscode (code.exe) command line arguments to immediately open a remote workspace folder over SSHVscode (code.exe) 命令行参数可立即通过 SSH 打开远程工作区文件夹
【发布时间】:2021-11-22 16:54:07
【问题描述】:

如果我想在 C:\ 下的常规本地文件夹上打开工作区,我可以执行以下命令:

code.exe C:\the-local-workspace-folder

是否有任何等效的命令可以打开远程 SSH 工作区?

我希望能够使用我的键盘启动器打开它们,而不是需要在 vscode 内部菜单中以繁琐的方式打开它们。

所以我需要一个常规的系统命令才能做到这一点。

我在这里查看了命令行参数:https://code.visualstudio.com/docs/editor/command-line - 但根本找不到有关远程工作区的任何信息。

我也尝试过类似的命令:

code.exe username@hostname.example.com:/workspace-folder
code.exe username@hostname.example.com/workspace-folder

...但他们不适合这个。

【问题讨论】:

    标签: visual-studio-code command-line vscode-remote


    【解决方案1】:

    根据issue tracking here,这看起来像是最近的修复。我已经用我自己的设置进行了测试,这很有效:

    "C:\Users\myusername\AppData\Local\Programs\Microsoft VS Code\Code.exe" \
        --remote ssh-remote+myubuntumachine /home/myusername/myprojectdirectory
    

    myubuntumachine 应该是CTRL+SHIFT+P/Remote SSH 上的 SSH 配置文件中的 Host myubuntumachine 中给出的名称:打开配置文件...

    (实际上,在我的机器上,我没有机器名称,但有某种哈希值,尽管两者都可以。)

    【讨论】:

    【解决方案2】:

    要开始使用,您需要:

    如果还没有OpenSSH compatible SSH client,请安装。

    安装Visual Studio CodeVisual Studio Code Insiders

    安装Remote Development extension pack

    阅读更多:https://code.visualstudio.com/docs/remote/ssh

    安装扩展:

    code.exe --install-extension ms-vscode-remote.remote-ssh
    

    Follow the step-by-step tutorial 或者如果您有一个简单的 SSH 主机设置,请按如下方式连接到它:

    F1 并运行 Remote-SSH: Open SSH Host... 命令。进入 您的用户和主机/IP 在输入框中采用以下格式 出现并按 Enter:user@host-or-ipuser@domain@host-or-ip 如果出现提示,请输入您的密码(但我们建议设置基于密钥的身份验证)。连接后, 使用文件 > 打开文件夹在主机上打开一个文件夹。

    您可以按 F1 调出命令面板并输入 Remote-SSH 以获取可用命令的完整列表。 command list

    您可以通过使用 --extensions-dir 命令行选项启动 VS Code 来更改位置。

    扩展安装在哪里?# 扩展安装在每个用户的扩展文件夹中。根据您的平台,该位置位于以下文件夹中:

    Windows %USERPROFILE%.vscode\extensions

    Linux ~/.vscode/extensions

    ma​​cOS ~/.vscode/extensions

    要运行远程 ssh 并在命令行中打开文件夹:

    code.exe --remote ssh-remote+root@server.com <your-directory>
    

    【讨论】:

    • 这不是他们要的。
    • @KenY-N 检查一下
    【解决方案3】:

    VSCode 1.63(2021 年 11 月)添加了选项 -n (issue 137529),以确保为远程 CLI 打开一个新窗口:

    以下选项已添加到远程 CLI:

    -n 打开与当前窗口相同远程的新窗口 -n --remote=wsl+ubuntu 打开不同遥控器的新窗口 -n --remote=local打开一个新的本地窗口

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-11
      • 1970-01-01
      • 2013-09-01
      • 2021-06-09
      • 1970-01-01
      相关资源
      最近更新 更多