Visual Studio Code new config setting in terminal profiles using Cmder - terminal

I am trying to integrate cmder into visual studio code as the default terminal, I used to configure like this in my settings.json.
{
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
"terminal.integrated.shellArgs.windows": [
"/k",
"C:\\Program Files\\cmder\\vendor\\init.bat"
],
}
But now visual code is telling me this configuration is deprecated.
So, I started to investigate VSC documentation, and it is saying I should import like this:
{
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"Git Bash": {
"source": "Git Bash"
},
"Cmder": {
"path": "C:\\Program Files\\cmder\\vendor\\init.bat"
}
},
"terminal.integrated.defaultProfile.windows": "Cmder"
}
But it is not working... is starts opening the terminal but closes immediately. Is there something I am missing?

You could try like this (leave the rest unchanged):
...
"Cmder": {
"path": "C:\\WINDOWS\\SysWOW64\\cmd.exe",
"args": ["/k", "C:\\Program Files\\Cmder\\vendor\\init.bat"]
}
...
Alternatively, you can also try with:
these paths:
"C:\\Windows\\Sysnative\\cmd.exe"
"C:\\Windows\\System32\\cmd.exe"
these args:
["/k", "C:\\PROGRA~2\\Cmder\\vendor\\init.bat"]
["/k", "C:\\Program Files^ (x86)\\Cmder\\vendor\\init.bat"]
one of the above in a single string instead of two

Related

how can I run commands in VSCode in VSCode tasks with password prompt?

I have this .vscode/tasks.json file:
{
"version": "2.0.0",
"tasks": [
{
"label": "Run mysql on startup",
"type":"shell",
"command": "sudo mysql.server start",
"presentation": {
"reveal": "always",
"panel": "new"
},
"runOptions": { "runOn": "folderOpen" },
"options": {
}
}
]
}
when I run sudo mysql.server start in the terminal, I have to add my password in a separate command.
I want:
combine the command with the password in one command.
get the password in a secure way (like using .env or from a secure file, etc).
by the way, I am using a mac OS.

How to automate Visual Studio Code startup?

I need to setup my development environment multiple times a day, I want to automate the process to a one-click solution.
The goal is to having a main script which opens up two VS Code instances, one for the frontend, one for the backend project.
The steps should be the following:
- open VS Code
- open Backend Project (located at e.g.: C:/myCompany/backend)
- run git pull
- open terminal
- run docker-compose up
- open split terminal
- run npm run start:dev
- open another vscode
- open terminal
- git pull
- open terminal
- run npm run start:dev
I am running windows, I can create very basic ps1 files, I know you can use terminal and run 'code' command to start an instance of VS Code. After that I don't find information what to do next.
I know there some kind of scripts you can run in Vs Code too, but I cannot put it all together.
There's a certain level of automation that can be achieved with VSCode's tooling itself.
Let's start with the backend part of the project. Inside C:/myCompany/backend create a folder .vscode and inside of it place two files: settings.json and tasks.json. They should be as follows:
// C:/myCompany/backend/.vscode/tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "git pull",
"type": "shell",
"command": "git pull",
"problemMatcher": [],
"runOptions": {
"runOn": "folderOpen"
}
},
{
"label": "docker-compose up",
"command": "docker-compose up",
"type": "shell",
"presentation": {
"reveal": "always",
"panel": "dedicated",
"group": "dev"
},
"group": "build",
"runOptions": {
"runOn": "folderOpen"
}
},
{
"label": "start:dev",
"type": "shell",
"command": "npm run start:dev",
"presentation": {
"panel": "dedicated",
"group": "dev"
},
"runOptions": {
"runOn": "folderOpen"
}
}
]
}
// C:/myCompany/backend/.vscode/settings.json
{
"task.allowAutomaticTasks": "on"
}
Similarly, under C:/myCompany/frontend create the same .vscode folder and the same two files under it; settings.json would stay the same, but tasks.json would be as follows:
// C:/myCompany/frontend/.vscode/tasks.json
{
"version": "2.0.0",
"tasks": [
{
"label": "git pull",
"type": "shell",
"command": "git pull",
"problemMatcher": [],
"runOptions": {
"runOn": "folderOpen"
}
},
{
"label": "start:dev",
"type": "shell",
"command": "npm run start:dev",
"presentation": {
"panel": "dedicated",
"group": "dev"
},
"runOptions": {
"runOn": "folderOpen"
}
}
]
}
To finish things up, the powershell script would be as simple as this:
code C:\myCompany\backend
code C:\myCompany\frontend
In previous VSCode versions it was necessary to invoke workbench.action.tasks.manageAutomaticRunning and then to choose Allow Automatic Tasks in Folder once for each folder, but that doesn't seem to be the case any more (the setting in settings.json seems to suffice).
For further customisation (e.g. task execution order and dependency), you can look at the documentation: https://code.visualstudio.com/Docs/editor/tasks. You can also experiment with running git pull right from the powershell script instead of the VSCode tasks.

I wanna make git bash but my default terminal but I'm getting an error because of another settings inside

Im trying to make git bash my main terminal but couldn't because of the sass live server compiler. Here is the code
terminal.integrated.profiles.windows":{"Git Bash":{"path":"C:\\Program Files\\Git\\bin\\bash.exe"}, },
"terminal.integrated.defaultProfile.windows": "Git Bash"
{
"liveSassCompile.settings.formats": [
// This is Default.
{
"format": "expanded",
"extensionName": ".css",
"savePath": "/css"
}
],
"explorer.confirmDelete": false,
"powershell.powerShellDefaultVersion": "Windows PowerShell (x86)",
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 500
}
The error Im getting is Expected a JSON object, array or literal.
VS Code is complaining that its settings file is not valid JSON, which it is indeed not. Try the following:
{
"liveSassCompile.settings.formats": [
// This is Default.
{
"format": "expanded",
"extensionName": ".css",
"savePath": "/css"
}
],
"explorer.confirmDelete": false,
"powershell.powerShellDefaultVersion": "Windows PowerShell (x86)",
"files.autoSave": "afterDelay",
"files.autoSaveDelay": 500,
"terminal.integrated.profiles.windows": {
"Git Bash": {
"path": "C:\\Program Files\\Git\\bin\\bash.exe"
},
},
"terminal.integrated.defaultProfile.windows": "Git Bash"
}

VSCode: How to open two terminals on startup with different directories

I want on startup (on folder open) two terminals.
These should start with different directories and should be in split mode. Is this possible?
I have this currently in tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"presentation": {
"echo": false,
"reveal": "always",
"focus": false,
"panel": "dedicated",
"showReuseMessage": true
},
"tasks": [
{
"label": "Create terminals",
"dependsOn": [
"First",
"Second"
],
// Mark as the default build task so cmd/ctrl+shift+b will create them
"group": {
"kind": "build",
"isDefault": true
},
// Try start the task on folder open
"runOptions": {
"runOn": "folderOpen"
}
},
{
// The name that shows up in terminal tab
"label": "First",
// The task will launch a shell
"type": "shell",
"command": "/bin/bash; cd /var/fpwork/",
// Set the shell type
// Mark as a background task to avoid the spinner animation on the terminal tab
"isBackground": true,
"problemMatcher": [],
// Create the tasks in a terminal group
"presentation": {
"group": "my-group"
}
},
{
"label": "Second",
"type": "shell",
"command": "/bin/bash; cd /var/",
"isBackground": true,
"problemMatcher": [],
"presentation": {
"group": "my-group"
}
}
]
}
This opens two terminals in split mode, but how can I specify different folders for them?
The lines
"command": "/bin/bash; cd /var/fpwork/"
and
"command": "/bin/bash; cd /var/"
just seem to ignore the cd command. How to specify the terminal folders?
The thing that worked for me is
"command": "/bin/bash --rcfile <(echo '. ~/.bashrc; cd /var')"
See How to invoke bash, run commands inside the new shell, and then give control back to user?

VSCode error in settings when trying to set Git Bash as default profile for terminal

I tried to set Git Bash as the default terminal in VSCode, but I can't do it successfully. I've tried following the next articles:
How do I use Bash on Windows from the Visual Studio Code integrated terminal?
How to Add Git Bash to VsCode
But they haven't resolved my issue.
I managed to generate profiles in settings.json, but Git Bash doesn't work for some reason unknown to me and VsCode shows an error.
My settings.json:
{
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"Git Bash": {
"source": "Git Bash",
"path": "C:\\git-sdk-64\\git-bash.exe",
"args": [
"--login",
"-i"
]
},
"Cygwin": {
"path": "C:\\cygwin64\\bin\\bash.exe",
"args": [
"--login"
]
}
},
"terminal.integrated.defaultProfile.windows": "Git Bash"
}
The error:
Does anyone know how to fix this?
My VsCode version:
Version: 1.57.1 (user setup)
Commit: 507ce72a4466fbb27b715c3722558bb15afa9f48
Date: 2021-06-17T13:28:07.755Z
Electron: 12.0.7
Chrome: 89.0.4389.128
Node.js: 14.16.0
V8: 8.9.255.25-electron.0
OS: Windows_NT x64 10.0.19042
Edit:
I use git SDK, which is like git-bash but not exactly. Maybe this is the problem?
this finally worked for me
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell"
},
"Command Prompt": {
"path": [
"${env:windir}\\Sysnative\\cmd.exe",
"${env:windir}\\System32\\cmd.exe"
],
"args": [],
"icon": "terminal-cmd"
},
"GitBash": {
"path": ["C:\\Program Files\\Git\\bin\\bash.exe"],
"args": [],
"icon": "terminal-bash"
}
},
"terminal.integrated.defaultProfile.windows": "GitBash"
}
I just met a same problem. And the solution on my VS Code 1.60.0 is also to rename Git Bash into GitBash.
During debugging using Developer Tools, I found VS Code always "merge" object values with the default values of a same key, so:
in VS Code, the Git Bash key has a default value of { source: "Git Bash" }
I once wrote {..., "Git Bash": { "path": "D:\\Git\\usr\\bin\\bash.exe", ... }}
and then the merged value is {..., "Git Bash": { "source": "Git Bash", "path": "...", ... }}
during a function named showProfileQuickPick, VS Code calls _detectProfiles
this function sends values of terminal.integrated.profiles.windows and terminal.integrated.defaultProfile.windows to its _primaryOffProcessTerminalService
the value of profiles is just the merged one
as a result, the object of Git Bash is somehow "illegal" and then ignored
On the contrary, GitBash means to declare a new profile object, so it should work.

Resources