bash - 如何在 WSL2 中运行的 vscode 中设置 bash

标签 bash visual-studio-code windows-subsystem-for-linux

我想使用类似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

但是,sourcebash 关键字,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/

相关文章:

c++ - 从 vscode C++ 调试步骤中排除文件?

regex - sed 命令 : regex in bash to exclude certain strings

linux - 调用 shell 脚本/。 bash 脚本中的 jar 文件

python - 在 vscode 中实现和改进 Python-Intellisense

linux - 分配给 AzureDevops 中的个人访问 token 、用于 GIT 的 "Scope of Access"应该有多宽?

bash - 某些颜色在 Windows 上的 bash 中无法正确呈现?

pip - windows10安装pip出错

linux - 有没有办法将 shell 脚本作为一个完整的任务运行(使用单个 PID)?

python - 如何从 RegEx(正则表达式)生成所有组合?

Python 泛型继承和 vscode 智能感知 (MSLS)