2

I would like to use something like 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.

I have added a ~/.vscode-server/server-env-setup and according to the logs it is found and executed, but my linux skills are quite basic and i can't figure out how to get my profile installed. I have tried

bash ~/.profile

...but that doesn't seem to do anything. I have also tried

#!/bin/bash
source ~/.profile

which gives me an error /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

UPDATE

The question of how to source a profile is answered below, but my problem with getting powerline-go to work in vs-code on WSL2 persists, but i moved that to a new question in order to close this one.

carl
  • 375
  • 4
  • 17
  • `bash ~/.profile` is going to execute your `.profile` file in a new subshell, then exit, effectively discarding the modification that were made. The keyword you are looking for is `source ~/.profile` – Aserre Dec 09 '19 at 14:03
  • Does this answer your question? [What is the difference between using \`sh\` and \`source\`?](https://stackoverflow.com/questions/13786499/what-is-the-difference-between-using-sh-and-source) – Aserre Dec 09 '19 at 14:05
  • @Aserre, i have also tried `source ~./profile` which gives me an error `/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`. Did some searching and found [this](https://askubuntu.com/questions/504546/error-message-source-not-found-when-running-a-script), so i tried adding `#!/bin/bash` as line one but i still get the same error when using source. – carl Dec 10 '19 at 10:57
  • could you show the content of your `/home/cber/.vscode-server/server-env-setup` file ? Could you tell us what happens when you put `readlink /proc/$$/exe` at the 1st line ? – Aserre Dec 10 '19 at 11:08
  • @Aserre, the file just currently looks like ```bash #!/bin/bash source ~/.profile ``` ... if i change it to ```bash readlink /proc/$$/exe source ~/.profile ``` ... it outputs `/bin/dash` – carl Dec 10 '19 at 11:16

1 Answers1

5

In order to persist your settings in your current shell, you need to source your config instead of just executing it (see this link for more details).

The problem is that vscode is using dash to load your config file instead of bash.

However, source is a bash keyword, and is not understood by dash. So you'll have to use the more portable syntax, ., in order to make it work with dash.

Try replacing your file by the following content (no need for #!/bin/bash) :

# if the profile file exists, we source it
if [ -f ~/.profile ]
then
  . ~/.profile
fi
Aserre
  • 4,916
  • 5
  • 33
  • 56
  • I realized after a few attempts that I had multiple vscode windows open and I needed to close all of them before the server-env-setup script would run. It also seems like vscode updated my $PATH variable without help of the script after doing this... – Peter Valadez Oct 16 '20 at 01:41