是否可以使用“代码"?在 SSH 终端中使用 SSH 扩展在本地机器上打开 VS Code 的命令? [英] Is it possible to use the "code" command in SSH'ed terminal to open VS Code on local machine with SSH extension?

查看:44
本文介绍了是否可以使用“代码"?在 SSH 终端中使用 SSH 扩展在本地机器上打开 VS Code 的命令?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我喜欢 VS Code 的一点是,当我在 WSL 中使用终端时,我可以运行 code file.txt,它会使用 WSL 在我的本地使用 VS Code 打开该文件远程分机.

Something I love about VS Code is that when I am using a terminal in WSL, I can run code file.txt, and it will open that file with VS Code on my local using the WSL remote extension.

是否可以用 SSH 做类似的事情?即,如果我通过 SSH 连接到远程主机,是否可以进行设置,以便运行 code file.txt 将在我的本地机器上打开 VS Code,通过远程 SSH 扩展连接到打开那个文件?

Is it possible to do a similar thing with SSH? I.e., if I am SSH'ed into a remote host, is it possible to set things up so that running code file.txt will open VS Code on my local machine, connected via the remote SSH extension to open that file?

推荐答案

您不应该做任何事情.VSCode 会根据您的 shell 自动将 path/PATH 设置为 path/PATH 环境变量中的 code .请参阅此回复.您可能会像我一样覆盖您的路径/路径.我不小心覆盖了 ~/.cshrc 中的 path~/.bashrc 中的 PATH 并且遇到了同样的问题.修复后,我可以在命令行上运行 code.which code 返回命令的位置.

You shouldn't have to do anything. VSCode automatically sets the path/PATH to the code in the path/PATH environment variable depending on your shell. See this response. You might be overwriting your path/PATH like I was. I was accidentally overwriting path in ~/.cshrc and PATH in ~/.bashrc and was running into the same issue. After fixing it, I can run code on the command line. which code returns the location of the command.

在我花时间弄清楚之前,我使用了下面提到的两种方法.两者都在 bash 中对我有用;您可以根据需要为您的外壳修改它.但真正修复您的路径/路径而不是使用这些方法.

Until I spent time to figure it out, I was using the two methods mentioned below. Both of which worked for me in bash; you can modify it for your shell as you see fit. But really fix your path/PATH rather than using these methods.

  1. code的位置添加到~/.bashrc

导出路径=${VSCODE_GIT_ASKPASS_NODE%/*}/bin:$PATH

  1. ~/.bashrc

别名代码=${VSCODE_GIT_ASKPASS_NODE%/*}/bin/code"


更多关于 pathPATH 此处这里

这篇关于是否可以使用“代码"?在 SSH 终端中使用 SSH 扩展在本地机器上打开 VS Code 的命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆