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.

5
  • 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 Commented Dec 9, 2019 at 14:03
  • Does this answer your question? What is the difference between using `sh` and `source`? Commented Dec 9, 2019 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, so i tried adding #!/bin/bash as line one but i still get the same error when using source. Commented Dec 10, 2019 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 ? Commented Dec 10, 2019 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 Commented Dec 10, 2019 at 11:16

1 Answer 1

6

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
Sign up to request clarification or add additional context in comments.

1 Comment

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...

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.