Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set environment variables when using Visual Studio Code with remote-ssh extension

I am trying to use Visual Studio Code with Remote-SSH extention (so I am working on a Windows machine while project files are on remote Linux server).

In order to build the project (C++ & CMake) I need to execute a script which sets up some environment variables.

Is there a way to execute such script automatically when vscode starts up its server?

It seems to be useless for me to call this script using vscode's terminal because then these variables are availiable only in this terminal session and not for the tools & extensions which vscode uses.

like image 551
NwMan Avatar asked Nov 25 '19 09:11

NwMan


People also ask

How do I connect to a remote server using SSH in VS Code?

In VS Code, select Remote-SSH: Connect to Host... from the Command Palette (F1, Ctrl+Shift+P) and use the same user@hostname as in step 1. If VS Code cannot automatically detect the type of server you are connecting to, you will be asked to select the type manually.

Is VS Code remote SSH safe?

VS Code Remote SSHSSH, or the secure shell protocol, lets you access a remote computer or virtual machine securely over a network connection. You can connect over SSH into another machine from Visual Studio Code and interact with files and folders anywhere on that remote filesystem.

How do I set environment variables in Visual Studio?

Developer Community. - select Environment in the left column, then click the "down arrow" and select <Edit...> - the Environment dialog should appear. (the second variable is concatenated to the value of the first one).

How do you change environment in VS Code?

Select and activate an environment# To select a specific environment, use the Python: Select Interpreter command from the Command Palette (Ctrl+Shift+P).


1 Answers

I've put something like this in my ~/.bashrc, I guess other login scripts may be used instead based on you shell, hope it helps:

if [[ $TERM_PROGRAM = 'vscode' ]]; then
    export DISPLAY=:100
fi
like image 55
Gianluca P. Avatar answered Sep 22 '22 07:09

Gianluca P.