如何在 WSL2 中设置 bash in vscode 运行

How to setup bash in vscode running in WSL2

我想使用 oh-my-bash in vscode using WSL2. However according to the 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: source: not found

更新

下面回答了如何获取配置文件的问题,但我的问题是获取 powerline-go to work in vs-code on WSL2 persists, but i moved that to a new question 以关闭此配置文件。

为了在当前 shell 中保留您的设置,您需要 source your config instead of just executing it (see 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