windows - 如何从 WSL (Ubuntu) 中启动 Windows 上 native 安装的 Atom 或 VSCode?

标签 windows ubuntu visual-studio-code atom-editor windows-subsystem-for-linux

我通过下载正在运行的安装程序在 Windows 10 上本地安装了 Atom 编辑器。现在我启动 WSL Ubuntu 发行版并希望从那里使用命令 atom . 启动 Atom (atom-editor)。或带有命令 code . 的 VSCode (visual-studio-code)

Atom 启动,但不在执行命令的目录中,而是显示来自 C:\\Windows 的文件.此外,Ubuntu WSL 终端显示以下错误消息:

atom .
grep: /etc/wsl.conf: No such file or directory
"\\wsl$\Ubuntu-18.04\home\wlad\projects\udemy\flask-bootcamp\Flask-Bootcamp-master"
CMD.EXE wurde mit dem oben angegebenen Pfad als aktuellem Verzeichnis gestartet.
UNC-Pfade werden nicht unterstützt.
Stattdessen wird das Windows-Verzeichnis als aktuelles Verzeichnis gesetzt.

抱歉,它是德语本地化的,但上面写着 UNC-paths are not supported
(还没有测试过VSCode)

那么如何从 WSL 中使用安装在 Windows 10 上的 Atom 或 VSCode 编辑器?

** 更新 **
截至今天(2020 年 4 月),在带有 WSL、VirtualMachines (VM) 甚至容器的 Windows 上使用 VSCode 有了更好的方法。查看 remote-development plugin对于 VSCode。

最佳答案

我创建了一个简短的脚本来处理我最常用的三个 atom 命令(我使用带有 WSL 的 Ubuntu):

  • atom
  • atom .
  • atom RELATIVE_PATH_FILE

  • 这个脚本没有优化,我相信很多人会发现边缘情况,但它为我完成了工作。要使用它,只需将其放入 ~/.local/bin/atom并通过运行 chmod +x ~/.local/bin/atom 使其可执行.您可能需要为 ~/.local/bin 重新启动 shell添加到您的路径中。为了简化一点,我将 ubuntu 安装的 WSL 网络驱动器映射到 U:。 ,所以你要么想要做同样的事情,要么在第 9 行相应地修改脚本。
    #!/bin/bash
    
    if [ -z $1 ]; then
      pushd /mnt/c > /dev/null
      /mnt/c/Windows/System32/cmd.exe /c "atom"
    else
      [[ $1 = "." ]] && path=$(pwd) || path=$(realpath $1)
    
      winPath=$(echo "U:$path" | sed -e 's/\//\\/g')
    
      pushd /mnt/c > /dev/null
      /mnt/c/Windows/System32/cmd.exe /c "atom $winPath"
    fi
    
    popd > /dev/null
    
    该脚本执行几个简单的步骤。首先,如果没有命令行参数,它只是使用 cmd.exe 调用 atom。没有论据。如果命令行参数是 . , 获取当前目录的路径,否则获取给定文件的绝对路径 realpath .使用 sed 将路径从 POSIX 转换为 Windows 格式在使用 cmd.exe 调用 atom 之前和以前一样,但带有路径参数。pushdpopd命令只是为了摆脱关于不支持 UNC 路径的烦人警告消息:
    ...
    CMD.EXE was started with the above path as the current directory.
    UNC paths are not supported.  Defaulting to Windows directory
    

    关于windows - 如何从 WSL (Ubuntu) 中启动 Windows 上 native 安装的 Atom 或 VSCode?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56976845/

    相关文章:

    php - PHP 的 MySQL 语法错误

    c++ - Ubuntu 中安排的 C++ Qt 应用程序中没有样式的窗口外观

    visual-studio-code - 为什么tasks.json : file format not recognized

    Angular 导入成本

    windows - git 如何在 Windows 上检测修改过的文件?

    windows - cmake add_subdirectory 错误仅适用于 cmake 命令行,但不适用于 Windows 上的 cmake-gui(在驱动器号的根目录下 check out 源)

    c++ - 如何获取 %AppData% 路径作为 std::string?

    Python while 循环不继续

    android - Kivy Buildozer 无法构建 apk,命令失败 : ./distribute.sh -m "kivy"d

    javascript - 尝试使用 ngFor 从数组进行插值时在 DOM 中获取 NaN