简体   繁体   English

在本地 VSCode 中打开远程文件夹,如 WSL2 中的“code.”

[英]Open remote folder in local VSCode like "code ."in WSL2

Is it possible to use $ code.是否可以使用$ code. in remote server ssh session just like I do in WSL when I want to open current working directory in remote host in local VSCode?在远程服务器 ssh session 中,就像我在WSL中一样,当我想在本地 VSCode 中打开远程主机中的当前工作目录时?

ADDENDUM: In local WSL, I can issue $ code.附录:在本地 WSL 中,我可以发出$ code. and that would open the current directory in VSCode which is installed on Windows 10.这将打开安装在 Windows 10 上的 VSCode 中的当前目录。

I am trying to get the same behavior in another remote Linux which I have connected to remotely through ssh .我试图在另一个远程 Linux 中获得相同的行为,我已通过ssh远程连接。 So when I am on that remote machine and issue $ code.因此,当我在那台远程机器上并发出$ code. it would open that directory in VSCode installed on local window.它将在本地 window 上安装的 VSCode 中打开该目录。

I don't imagine this would be simple to do but I certainly share your desire to want to be able to do it.我不认为这很容易做到,但我当然和你一样希望能够做到这一点。

Problem问题

Here's an explanation of why it doesn't work, and a hint at why it's probably quite a difficult thing to setup:以下是它为什么不起作用的解释,以及为什么它可能很难设置的提示:

The way code.方式code. works from WSL (or PowerShell) is by launching VS Code in the given directory (passed as the first argument as the dot). WSL(或 PowerShell)的工作方式是在给定目录中启动 VS Code(作为第一个参数作为点传递)。

When you run code from WSL it uses wslpath to convert the path to the Windows accessible one, and the WSL magic executes code.exe (which is, after all, a Windows binary and not a Linux one) in Windows with the WSL path ( \\wsl$... ); When you run code from WSL it uses wslpath to convert the path to the Windows accessible one, and the WSL magic code.exe (which is, after all, a Windows binary and not a Linux one) in Windows with the WSL path ( \\wsl$... );

Theory理论

In order for this to work you need to achieve three things:为了使它起作用,您需要实现三件事:

  • Work out which remote you're connected to, and be able to pass that information to vscode找出您连接到哪个遥控器,并能够将该信息传递给 vscode
  • Execute code.exe on your local machine, but from your remote terminal在本地计算机上执行code.exe ,但从远程终端执行

Ideas想法

A couple of ideas you could play with if you wanted to try and implement it:如果您想尝试实现它,可以使用一些想法:

  • A script on your remote could output a vscode:// URL for you to click (or find a way to get your client to auto-load it).您的遥控器上的脚本可以 output a vscode:// URL 供您单击(或找到让您的客户端自动加载它的方法)。
  • You might be able to use a forwarded port in your SSH session to contact something on your PC (perhaps custom made, or maybe with Windows RDP or a telnet/ssh server perhaps?)您可能可以使用 SSH session 中的转发端口来联系您 PC 上的某些东西(也许是定制的,或者也许是 Windows RDP/ssh 服务器?
  • Perhaps mount a local directory as part of your SSH connection (I don't know all the edges of SSH but it does a lot of cool stuff? SCP might help?) and be able to execute/trigger things?也许挂载一个本地目录作为 SSH 连接的一部分(我不知道 SSH 的所有边缘,但它做了很多很酷的事情?SCP 可能有帮助?)并且能够执行/触发事情?

Just some musings, It's not something I need enough to put any effort into it.只是一些沉思,这不是我需要付出任何努力的东西。 but I came across your question looking for something else and found it interesting, Hope that's helpful to anybody, any thoughts/feedback is welcome!但我在寻找其他东西时遇到了你的问题,发现它很有趣,希望这对任何人都有帮助,欢迎任何想法/反馈!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM