我想使用类似oh-my-bash的东西在 vscode 中使用 WSL2。然而根据docs :
When VS Code Remote is started in WSL, no shell startup scripts are run. This was done to avoid issues with startup scripts that are tuned for shells. If you want to run additional commands or modify the environment this can be done in a setup script
~/.vscode-server/server-env-setup
(Insiders:~/.vscode-server-insiders/server-env-setup
). If present, the script is processed before the server is started.
我添加了一个 ~/.vscode-server/server-env-setup
并根据日志找到并执行了它,但我的 Linux 技能非常基础,我无法理解了解如何安装我的个人资料。我已经尝试过了
bash ~/.profile
...但这似乎没有任何作用。我也尝试过
#!/bin/bash
source ~/.profile
这给了我一个错误/mnt/c/Users/cber/.vscode/extensions/ms-vscode-remote.remote-wsl-0.40.3/scripts/wslServer.sh: 3:/home/cber/.vscode-server/server-env-setup:来源:未找到
更新
下面回答了如何获取配置文件的问题,但我在获取 powerline-go 时遇到问题在 WSL2 上的 vs-code 中工作仍然存在,但我将其移至 new question为了关闭这个。
最佳答案
为了在当前 shell 中保留您的设置,您需要 source您的配置而不是仅仅执行它(有关更多详细信息,请参阅 this link)。
问题是 vscode 使用 dash
加载您的配置文件,而不是 bash
。
但是,source
是 bash
关键字,dash
无法理解。因此,您必须使用更可移植的语法 .
,才能使其与 dash
一起使用。
尝试用以下内容替换您的文件(不需要 #!/bin/bash
):
# if the profile file exists, we source it
if [ -f ~/.profile ]
then
. ~/.profile
fi
关于bash - 如何在 WSL2 中运行的 vscode 中设置 bash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59249670/