8

I have the case that I need to use VS Code installed on Windows 10 and run it with the extension Remote - SSH on a RHEL 7.x.
The default RHEL 7.x runs with git 1.8.x. I have installed a newer git version but this is not in the default $PATH environment.

I have found this instructions https://code.visualstudio.com/docs/remote/wsl#_advanced-environment-setup-script which describe how to set the environment variables specifically for VS Code when usind WSL.

If you want to run additional commands or modify the environment this can be done in a setup script ~/.vscode-server/server-env-setup

This does seem to work only if you use WSL. Why does this not work with the Remote - SSH extension?

My special case is that I only want and need the git>=2 while usind VS Code. When I am connected regularly via ssh I would like and need the OS default tools and settings.
This gives me the special request that I don't want to edit the ~/.bashrc, ~/.cshrc or any other user environment files.
I would like to be able to edit the environment for VS Code only. Some kind, maybe like:

#!/bin/bash
export PATH=/opt/rh/rh-git29/root/usr/bin\:$PATH
export LD_LIBRARY_PATH=/opt/rh/httpd24/root/usr/lib64:$LD_LIBRARY_PATH
...
#!/bin/csh
setenv PATH /opt/rh/rh-git29/root/usr/bin\:$PATH
setenv LD_LIBRARY_PATH /opt/rh/httpd24/root/usr/lib64:$LD_LIBRARY_PATH
...

Is there anything I have not found yet where I can make my requests to work or would this be some kind of request to the VS Code Team?

Regards.

nsolthe
  • 147
  • 1
  • 1
  • 6

2 Answers2

10

I think I found the solution in this issue comment and the follow-up response:

  • When vscode-server initially starts, it uses a login shell, sourcing .profile in your home directory.
  • However, any following interactive shells started through VS Code are non-login shells and thus only source .bashrc
  • A complication in fiddling with this is that vscode-server apparently caches the environment during its lifetimes, so changes to these dotfiles don't become visible until the server is restarted.
Andreas
  • 116
  • 2
  • 3
  • 10
    Note to self: the relevant command is called "Remote-SSH: Kill VS Code Server on Host". But it didn't work properly for me, so I went for good old server-side `killall node`. – Martin Cejp May 18 '21 at 15:28
  • After many VSC updates I started to use the `"git.path": ""` in the settings.json it is working fine with ssh repositories. – nsolthe Jun 29 '21 at 08:33
  • In my case, I must create a ` ~/.bash_profile` : `source ~/.zshrc` then `killall node`. Work well, add things to settings not work for me. – Tiana987642 Jun 21 '22 at 10:24
0

I have a better solution to minimize the proxy scope

export http_proxy=<proxy here>
export no_proxy=<no proxy here>
while IFS= read -r _file; do
    if ! grep -s -q "export http_proxy=" "${_file}"; then
        sed -i -e "/^ROOT/i export http_proxy=${http_proxy}" -e "/^ROOT/i export https_proxy=${http_proxy}" -e "/^ROOT/i export no_proxy=${no_proxy}" "${_file}"
    fi
done < <(find ~/.vscode-server/bin -type f -name "server.sh")
Tom Shen
  • 1,747
  • 1
  • 11
  • 6