How to set from command line "select interpreter" of "ms-python.python"? - visual-studio-code

I have installed this extension.
Is there any way I can set the select interpreter path from command line?

You can set it through the file settings.json either in vscode user domain or in a vscode workspace .vscode path.
{
//...
"python.defaultInterpreterPath": "python" // the default path
}
If you want you could modify settings.json through commandline.

Related

How can I change the default shell for a specific workspace in VS Code? (Not globally)

I want to set a specific shell for only one workspace, which pops up when I press CTRL+Shift+`. But not globally for all workspaces.
For example, my default VS Code shell is the Windows Command Prompt. I have only one project in which I need Git Bash to be the default shell.
I tried creating a json setting file in the workspace's .vscode/ directory but I don't know what setting to change there.
Create a workspace settings.json (in the workspace's .vscode/settings.json file), and in it, configure whichever of the following variables that you wish:
"terminal.integrated.defaultProfile.linux": null, // TODO: pick one
"terminal.integrated.defaultProfile.osx": null, // TODO: pick one
"terminal.integrated.defaultProfile.windows": null, // TODO: pick one
You can edit what profiles are defined by editing the following settings:
"terminal.integrated.profiles.linux": { ... },
"terminal.integrated.profiles.osx": { ... },
"terminal.integrated.profiles.windows": { ... },

Change path for git bash terminal in VSCode

When I use a git bash terminal in VSCode, I get the error
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
That's because the default path for git bash is C:\Program Files... (see pic bellow)
I tried to install a portable Git to the folder without spaces and then in VSCode to change a git path, but it didn't change the path for git bash. Also, I tried to add the "path" parameter in a settings.json, but it looks like the predefined terminals use the default path, not the custom ones defined in the settings.
"Git Bash": {
"path": "C:\\Windows\\SysWOW64\\Git\\bin\\Bash.exe"
}
How can I set the custom path for the git bash terminal?
Terminal path pic
To change the installation path of Git Bash, try renaming "Git Bash" to "Git_Bash". VS Code seems to prefer the default path over any customized path for Git Bash due to a bug. I installed Git under D:\Program Files, so I did this:
{
"terminal.integrated.defaultProfile.windows": "Git_Bash",
"terminal.integrated.profiles.windows": {
"Git_Bash": {
"path": "D:\\Program Files\\Git\\bin\\bash.exe",
"icon": "terminal-bash"
}
}
}
In my case what helped me was to change git.path in settings.json
Press CTRL+SHIFT+P
Type Open Settings
Choose Preferences: Open User
Settings (JSON)
Change git.path parameter to that
"git.path": "C:\\PROGRA~1\\Git\\bin\\git.exe",
The explanation found here:
The space in folder name breaks the prompt so in your settings.json
file make sure you update the path "Program Files" to simply
"PROGRA~1" instead

VSCode clang-format Xaver extension with no parent location for .clang-format

I would like to configure the VSCode Xaver extension to use a .clang-format file that is not in the parent folder, E.g. on the command line you could do this
"-style=file:<format_file_path>" to explicitly specify the configuration file path.
I have tried these settings below,
"clang-format.executable": "/usr/bin/clang-format-15",
with
"clang-format.style": "file:../40_scripts/shared",
or even
"clang-format.style": "file:${workspaceRoot}/40_scripts/shared",
and even,
"clang-format.assumeFilename": "${workspaceRoot}/40_scripts/shared/.clang-format",
But i can't get it to work, i see this in the extensions output window
"Error reading ${workspaceRoot}/40_scripts/shared/.clang-format: No such file or directory".
Is it possible with this extension to change the path to the .clang-format file? Thanks.

Set integrated Terminal name in VSCODE with settings.json

There's a few questions related to renaming or setting a terminal profile:
Change Integrated Terminal title in vscode
VSCode integrated terminal argument: current filename
But if you want to define this via settings.json per folder, how would you do it?
The answer is that it can only be done for the workspace.
Ref profile
Ref settings
Workspace.code-workspace eg:
{
"settings": {
"powershell.powerShellDefaultVersion": "PowerShell (x64)",
"python.envFile": "${workspaceFolder}/.venv",
"terminal.integrated.profiles.windows": {
"myprofilename": {
"source": "PowerShell",
"overrideName": true,
"icon": "terminal-powershell"
}
}
}
}
This will create the myprofilename as a selection for new terminal options.
However, if you want to set the default in a multi root workspace, at a folder level:
eg: somefolder_in_workspace/.vscode/settings.json:
{
"terminal.integrated.defaultProfile.windows": "myprofilename"
}
You'll see the line greyed out with a message if you hover: This setting cannot be applied in this workspace. It will be applied when you open the containing workspace folder directly.
This is how the documentation explains the behaviour:
To avoid setting collisions, only resource (file, folder) settings are applied when using a multi-root workspace. Settings that affect the entire editor (for example, UI layout) are ignored. For example, two projects cannot both set the zoom level.
So the answer is no, for folders in multi root workspaces, but yes, if you want the name for the workspace terminal

Change default working directory for VS Code terminal

Is it possible to change the working directory for new integrated terminal windows in Visual Studio Code?
I have opened the folder /path/to/project in Code, so when I open a new terminal windows, it starts in that folder. I would like the terminal to open in /path/to/project/app so that I don't have to cd to that folder every time. Is it possible to configure this in settings.json?
It turns out this was fairly easy to find in the documentation at https://code.visualstudio.com/docs/getstarted/settings.
The setting that controls this is
// An explicit start path where the terminal will be launched, this is used
as the current working directory (cwd) for the shell process. This may be
particularly useful in workspace settings if the root directory is not a convenient cwd.
"terminal.integrated.cwd": "",
This can be added to settings.json in the .vscode folder. Absolute and relative paths are supported, so
"terminal.integrated.cwd": "app"
and
"terminal.integrated.cwd": "/path/to/project/app"
will both work.
if you are changing your directory in your .bashrc or .zshrc file to your home directory (cd ~/ or cd $HOME/) then your vscode console will use the directory that you have specified.
Bellow is a little code you can use in your .bashrc or .zshrc to address this:
if [ "$NAME" != "Code ]; then
cd ~
else
cd $OLDPWD
fi