I have always had issues understanding how VSCode process environment variables on Windows. Currently, I am trying to integrate Cmder with VSCode as my shell using the json below that I found on Github:
"terminal.integrated.shell.windows": "cmd.exe",
"terminal.integrated.env.windows": {
"CMDER_ROOT": "[cmder_root]"
},
"terminal.integrated.shellArgs.windows": [
"/k",
"%CMDER_ROOT%\\vendor\\bin\\vscode_init.cmd"
],
I was trying to replace "[cmder_root]" with a variable defined in the OS but cannot get VSCode to recognize it. When I create the variable as a System variable, if I run set at the cmd.exe prompt of the integrated terminal, it shows the new variable name and the value I set it to but VSCode won't use it because it will not start Cmder when I open a terminal.
If I define the variable in the OS as User variable, running set inside the integrated terminal no longer displays that variable with the value I set it to. It displays it as CMDER_ROOT=%CMDER_ROOT%.
I finally got Cmder to work by hard coding the path in the settings.json file but it just made me want to find out what I am doing wrong.
Related
I would like to be able to cd into a folder that is added to a system as a system variable in Windows 11. Here is a visual representation of the problem:
As you can see, windows command prompt is able to "resolve" variables from the "User variables" section of the Environment variables configuration in Windows, however variables from the "System variables" aren't.
I need to cd into %VS140COMNTOOLS% folder but as you can see it won't be resolved by the command prompt. Is this by design?
VS140COMNTOOLS also doesn't appear in set output.
How can I navigate into %VS140COMNTOOLS%?
System variables and user vars end up in a single environment block. When expanding env vars, there's no concept of user/system. User vars override system vars.
Also: each process gets its own copy of env vars which is resolved when the process launches. Therefore, if a process appears to be "missing" an env var, one of the following happened:
The variable was set after the process launched. For example maybe this command prompt was open during the installation of something that created an env var. You'll need to re-launch the command prompt to get the var.
OR, the process modified it / removed it.
I just found that i cannot run most commands in windows cmd, such as "git", "java", "node".
I found a lots of answers telling me to set environment variables, the weird thing is, the environment variables looks good to me, and i can actually run these commands in powershell or git bash, but none of them works in windows cmd.
Hope anyone can give me some advise, thank q
As I understand,you are not able to run several commands in windows cmd.
Windows PowerShell is the new Microsoft shell that combines the old cmd functionality with a new scripting/cmdlet instruction set with built-in system administration functionality, so there would be several commands which would work in PowerShell but not in Command Prompt.
Use setx.exe to set persistent environment variables via Command Prompt using following command -
setx [variable_name] "[variable_value]"
Please note, setx.exe does not set the environment variable in the current command prompt, but it will be available in subsequent command prompts.
I have a requirement where I need to set a custom environment variable called CLUSTER_ENV = '#fooURL'
The steps I have followed are:
Open terminal, open bash_profile and save CLUSTER_ENV='#foo'. When I do echo $CLUSTER_ENV , I get blank output.
I did the same thing in the bashrc file and in this case, the $CLUSTER_ENV shows the value only when I run it in the same terminal window.
Which is the best or recommended way to permanently set the environment variable on a Mac?
Im running El Capitan.
I have gone through these links for reference:
http://osxdaily.com/2015/07/28/set-enviornment-variables-mac-os-x/
Mac OS X 10.9 - setting permanent environment variables
As you will normally do on any Linux distro: export CLUSTER_ENV=my.url.com which will have to be added to ~/.bash_profile
Having just installed VScode I have noticed as it uses Bash by default on OSX, with the shell's default prompt of bash-3.2$; consequently, I cannot see the current working directory. It means having to type 'pwd' and 'ls' quite frequently which is obvious quite tedious.
I have tried changing the default shell in the settings to
"terminal.integrated.shell.osx": "/Applications/Utilities/Terminal.app"
or
"terminal.integrated.shell.osx": "/Applications/iTerm.app"
This doesn't seem to work, have I made a mistake here?
I would also like to know if I am limited to bash, can I configure it to display the working directory instead of simply bash-3.2$ ?
See this screenshot of how the VSCode integrated terminal looks by default
Thanks in advance!
I use Ubuntu, and only add the following lines to the end of ~/.bashrc:
if [ "$TERM_PROGRAM" = "vscode" ]; then
PS1='\$ '
fi
Try it and let me know if it works on your OS.
You can set your prompt to contain the current working directory by defining PS1 as follows:
PS1="\w $"
The $ is just some visual sugar. There all manner of things you can have your prompt display. Put the definition in your ~/.bashrc or ~/.profile for it to be set when you login.
Check out the Controlling the Prompt section of the GNU Bash manual for details.
If you are not accustomed to editing your bash init files you can do it with Visual Studio Code by going to View->Command Palette and execute the following command (one-time only):
Install 'Code' command in path
Then open the integrated terminal and type the following:
code ~/.bashrc
Then add the PS1 definition to the bottom of that file.
I am using Scientific Linux 6.1. To run a program (DS9) I need to set this environment variable:
export XPA_METHOD=local
So I saved it in .bashrc and there is no problem when I run the program from the bash terminal. But when I run it in the GUI (for example by clicking on "Open with ds9" in nautilus), this variable is not recognized.
I would really appreciate if anyone could help me in setting the environment variable in GNOME.
Add it to ~/.profile instead of .bashrc
Edit: Log off and on again for the change to take effect.