cmderdev / cmder

Lovely console emulator package for Windows
https://cmder.app
MIT License
25.74k stars 2.02k forks source link

Question: Opening an External terminal from vscode with Windows Terminal using cmder #2842

Closed BartaG512 closed 1 year ago

BartaG512 commented 1 year ago

Question

When I run the openInTerminalcommand in vscode. The terminal should open at the location of the current file. But it opens up at 'C:\Windows\System32' path.

I have followed this https://github.com/cmderdev/cmder/wiki/Seamless-Windows-Terminal-Integration wiki set the cmder profile in wt and in my vscode settings.json I have set "terminal.external.windowsExec": "wt.exe",

Can I get some help with this issue? Is there any known way to achieve this?

Checklist

DRSDavidSoft commented 1 year ago

Please post the relevant configuration sections for Windows Terminal and VS Code, so we can replicate the issue.

Also, can you please describe in detail what is the expected behavior which isn't the case right now?

Is it that the Windows Terminal opens with the correct Cmder profile but the wrong working directory, or rather it doesn't launch Cmder profile? Or a combination of both?

Also, screen shots will be appreciated.

BartaG512 commented 1 year ago

The Windows Terminal the default profile settings:

            {
                "commandline": "cmd.exe /k \"d:\\Programs\\cmder\\vendor\\init.bat\"",
                "elevate": true,
                "guid": "{cca0b225-8a85-4a08-b151-2654a769716c}",
                "hidden": false,
                "icon": "D:\\Programs\\cmder\\icons\\cmder.ico",
                "name": "Cmder",
                "startingDirectory": null,
                "tabTitle": "Cmder"
            },

In vscode settings.json set the following config: "terminal.external.windowsExec": "wt"

Steps to reproduce: Open any project folder Select a file in the vscode explorer The parent directory of the file should be the starting directory of the new terminal. Then press Ctrl + Shift +P Find command and run : Open New External Terminal

In the new opened terminal working dir wrongly is "C:\Windows\System32"

After some serach I found the problem. I am using vscode version 1.73.1 and I found a related fix for this with this commit https://github.com/microsoft/vscode/commit/59328a42921c1eab8d0d416c59929d2f36bc3c68

Since new vscode versions breaking the compatibility with some of my extensions, I don't want to update yet. I have managed to make it work with vscode v1.73.1. by changing the vscode settings terminal.external.windowsExec configuration to a bat file containing this:

@start wt.exe -d %cd% 
@exit
chrisant996 commented 1 year ago

Yes, maybe this is an issue in VSCode.

Also, try removing the line "startingDirectory": null,. That tells VSCode "I'm overriding the starting directory, and you should use { no directory }". That will likely result in VSCode using an empty string as the directory, which will likely result in the OS using the system directory.

BartaG512 commented 1 year ago

image "startingDirectory": null - means use the parent process directory which is "C:\Windows\System32" in the case of cmd.exe

Deleting doesn't fix it.

I think we can close the issue, since I found a solution.