通过下载运行安装程序,我已经在Windows 10上本地安装了Atom编辑器。现在,我启动WSL Ubuntu发行版,并希望使用命令atom .或VSCode (visual-studio-code)命令code .启动Atom (原子编辑器)。
Atom启动,但不是在执行命令的目录中,而是显示来自C:\\Windows的文件。此外,Ubuntu终端显示以下错误消息:
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 10中安装的或VSCode编辑器呢?
** 更新 **截至目前(2020年4月),在Windows / WSL、VirtualMachines (VM)甚至容器上使用VSCode的方法要好得多。查看远程开发插件中的VSCode。
发布于 2019-07-13 10:51:37
在博客帖子 @Wlad提到的“已知问题”部分中,有以下几个方面:
访问Linux文件与访问网络资源一样,任何访问网络资源的规则仍然适用,例如:当使用CMD时,cd \wsl$\Ubuntu\home将无法工作(因为CMD不支持UNC路径作为当前目录),但是复制\wsl$\Ubuntu\home\somefile.txt C:\dev\将工作。
因此,由于Atom可以使用cmd.exe从命令行(可能是一些批处理文件)启动自己,并且考虑到cmd.exe不能将网络资源作为当前目录打开( WSL目录被视为当前目录),所以当您试图从WSL启动Atom时,出现了失败。
实际上,在VS代码中,有一个更好的解决方案可以直接从WSL启动VS代码:VS Code Remote。
您可以采取以下步骤使VS代码能够直接从WSL shell启动:
Remote - WSL到VS代码;code .时,VS代码远程服务器将自动安装,VS代码将很快启动。通过使用VS Code Remote,您不仅可以打开VS代码中的目录,而且还可以在许多其他方面受益:例如,您可以使用WSL作为VS代码中的集成shell,并直接从VS代码在WSL中运行程序。
这里是VS Code Remote - WSL的官方文档。
发布于 2020-10-12 20:14:12
我创建了一个简短的脚本来处理我使用最多的三个atom命令(我在WSL中使用Ubuntu ):
atomatom .atom RELATIVE_PATH_FILE这个脚本没有被优化,我相信很多人会找到边缘案例,但是它完成了我的工作。要使用它,只需将其放在~/.local/bin/atom中,并通过运行chmod +x ~/.local/bin/atom使其可执行。您可能需要重新启动shell,以便将~/.local/bin添加到您的路径中。为了简化一些事情,我将我的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,但使用path参数。
pushd和popd命令只是为了消除不支持UNC路径的恼人的警告消息:
...
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory发布于 2022-03-14 14:38:14
想要从WSL运行Atom,我来到了这里,但不幸的是,公认的答案没有提到原子,而其他与原子相关的解决方案不再起作用。
以防有人在谷歌上搜索这个问题,然后在这里结束。这里有一个实际的解决方法(它将在新的Atom更新中中断)。
C:\Users\{username}\AppData\Local\atom\app-{version}\ (在本文发布时,版本是1.60.0所以app-1.60.0 )。- Use the path mentioned above as the default path contains a bash executable that will be run fail to run in wsl.
- Here's where it will break in future updates. The fix is to update the env in windows to the new path since the folder where the exe is located will change to match atom's version..bashrc或.zshrc中添加以下内容- Important to be added in `.bashrc` or `.zshrc` as making a separate script in `/usr/bin` will always make atom to open in the `C:/Windows` folder.function _atom () { exec nohup atom.exe "$@" &> /dev/null & } # Do not output in terminal and do not block the terminal. Also send the command arguments to atom.
alias atom="_atom"https://stackoverflow.com/questions/56976845
复制相似问题