Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Starting directory no longer respected #878

Closed
nphmuller opened this issue May 17, 2019 · 57 comments
Closed

Starting directory no longer respected #878

nphmuller opened this issue May 17, 2019 · 57 comments
Labels
Area-Settings Issues related to settings and customizability, for console or terminal Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. Resolution-Won't-Fix We're just really obstinate about this. There's probably a good reason.
Milestone

Comments

@nphmuller
Copy link

nphmuller commented May 17, 2019

Commit where this occurs: e0f131121b08dc5d6485e4bd985ac2c7e32b6339
Commit where this didn't occur yet: d5b8e7c32f7a419a7d467eab038251ee529056e6

Since the startingDirectory profiles.json setting was introduced (which is set to %USERPROFILE% by default), the current starting directory is no longer respected and the terminal always starts in %USERPROFILE%.

The startingDirectory setting is great to make sure the terminal doesn't always start in c:\windows\system32. It might however be better that its not used when starting Windows Terminal from a folder.

With starting WT from a folder I mean launching wt.exe (or wtd.exe) from an open cmd, or in Windows Explorer via its address bar.

The folder of the parent cmd process (or Explorer process) should then be used by default and startingDirectory should be used as a fallback. For example, when launching Windows Terminal from the start menu.

Steps to reproduce

  • Make sure startingDirectory is set to %USERPROFILE%:
{
	...
	"profiles": [{
			"startingDirectory": "%USERPROFILE%",
		}, {
		...
		}
	],
	...
}
  • Open an explorer window in a random folder (for example the root of the C drive)
  • Type wt (or wtd) in the address bard

Expected behavior

Windows Terminal should open with the terminals path set to the folder opened in explorer. In the example this would be the root of the C drive: C:\.

Actual behavior

Windows Terminal opens with the terminals path set to the user profile path.

@ghost ghost added the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label May 17, 2019
@DHowett-MSFT
Copy link
Contributor

DHowett-MSFT commented May 17, 2019

Oh, boy. You're totally right, this is a regression. It also breaks Scott Hanselman's "Open WT here" shortcut.

not used when starting Windows Terminal from a folder

So there's a problem. C:\Windows\System32 is a folder. I'd rather not detect "folders we care about" versus "folders we don't care about," as those two lists can get pretty long.

Maybe the right decision is to return {profile}.startingDirectory to being fully optional and revert parts of #604? @fghzxm will probably have an opinion here.

There's a split in user desire here: some people want the profile to indicate a starting directory, and some want WT to launch whatever profile you specify on the command line (#607) in the directory in which they start it. Hmm.

@DHowett-MSFT DHowett-MSFT added Area-Settings Issues related to settings and customizability, for console or terminal Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels May 17, 2019
@nphmuller
Copy link
Author

So there's a problem. C:\Windows\System32 is a folder.

Ah. Without checking how it actually worked, I kind of assumed it was detectable if the cmd (or other) process was launched directly vs if it was launched in a folder. But I guess since cmd.exe is in PATH its basically the same for the process and only the cwd differs.

Maybe the right decision is to return {profile}.startingDirectory to being fully optional and revert parts of #604?

I like the current default of startingDirectory being the home directory. But if I had to choose between either home directory vs cwd, I'd choose cwd. Of course its just my opinion though...

@fghzxm
Copy link
Contributor

fghzxm commented May 17, 2019

I think we can let wt.exe have a command line option

-p "P:\ath\to\some\directory"

and use that path for the starting directory, otherwise respecting the profile settings. This way you can type wt.exe -p . and get the behavior you want.
We probably should also have a look at how terminal emulators on other platforms behave in this aspect, but I think gnome-terminal always launches the shell in my home directory...

I don't think having 2 different behaviors depending on whether the parent process is cmd.exe, explorer.exe or some other is a good thing because

  • The differing behaviors are confusing to the user, and
  • The user could still launch wt.exe from msys2 bash, cygwin bash or any other alternative shell of which we would have to maintain a list that can never be exhaustive.

(Plus, I guess since Start now has its own process StartMenuExperienceHost.exe, the actual parent of the processes launched from Start will be that process instead?)

@nphmuller
Copy link
Author

This way you can type wt.exe -p . and get the behavior you want.

Great solution! Maybe the the -p parameter can also be used as the default (unnamed) parameter.
That way we can even use wt.exe .. Which looks like the workflow many apps use (explorer ., code .)

I don't think having 2 different behaviors depending on whether the parent process is cmd.exe, explorer.exe or some other is a good thing because

Totally agreed. The solution you mentioned (-p) is simple and predictable.

@DHowett-MSFT
Copy link
Contributor

We’ll have to converge with the people who want wt.exe cmd and wt.exe ssh example@example.com, plus the people who want wt.exe {profileguid}. Let’s talk about that in #607.

@fghzxm
Copy link
Contributor

fghzxm commented May 17, 2019

@nphmuller I would rather like to reserve the unnamed parameter for the profile name, which I think is more useful (of course this is up to personal tastes).

@nphmuller
Copy link
Author

@fghzxm For my personally they both are about just as important. So that doesn't help. 😁

My main point is: Bash (WSL), cmd, PowerShell, Windows Explorer and VSCode (Explorer and VSCode via the . parameter) implemented a pattern where I could simply type the name of the executable, and it would open in the current directory. When starting via the start menu (or Run) it starts in the home directory, (or in a default view in the case on Explorer and VSCode).

I think it'd be nice if WT could also implement this widely used pattern. Using a -p parameter would work, but it would make this a bit harder the guess, and harder to use because it requires WT specific know-how.

Sorry for not coming up with a better solution. Just wanted to reiterate the point.

@zadjii-msft zadjii-msft added this to the Terminal Backlog milestone Jun 19, 2019
@ffes
Copy link

ffes commented Jun 24, 2019

My profile has "commandline": "wsl.exe -d Ubuntu". I expect it to start in $HOME aka ~ and not in /mnt/c/Windows/SYSTEM32.

Know that startingDirectory is not set for this profile. That is how the profile was created when installed on my machine.

I am using the current store version: 0.2.1715.0

@fghzxm
Copy link
Contributor

fghzxm commented Jun 24, 2019

@ffes You will get /mnt/c/Windows/System32 if you invoke the plain wsl command. You want wsl ~.

@ffes
Copy link

ffes commented Jun 24, 2019

@fghzxm You're right.

The default profile you get when you install it for the first time should have the ~ added, but that is most likely another issue.

@bmlynarczyk
Copy link

I'm totally agree with @nphmuller from this comment. In my workflow there is no time to remember about -p parameter. For me behavior same like cmd, powershell, sh ... is killer feature of Windows explorer. It would be nice when wt will be compatible with shuch a behavior.

@twopoint71
Copy link

+1
In version: 0.3.2171.0 startingDirectory is not respected. Strictly defaults to %USERPROFILE% where I want "~" for default wsl.exe shells.

@DHowett-MSFT
Copy link
Contributor

That's not exactly true. The problem here is that startingDirectory is a windows path.

@joemaller
Copy link

joemaller commented Aug 14, 2019

@DHowett-MSFT is correct. "startingDirectory": "~" doesn't work for WSL shells, but this does:

  "startingDirectory": "\\\\wsl$\\Ubuntu\\home\\joe"

@ipat8
Copy link

ipat8 commented Aug 29, 2019

@DHowett-MSFT is correct. "startingDirectory": "~" doesn't work for WSL shells, but this does:

  "startingDirectory": "\\\\wsl$\\Ubuntu\\home\\joe"

This workaround no longer seems to be functioning with the latest update. The issue however still remains.

(When I say latest update, I am referring to the build available via the MSFT store.)

@nsheaps
Copy link

nsheaps commented Sep 1, 2019

@ipat8 I just installed it this seems to be working for me (installed today from https://www.microsoft.com/store/productId/9N0DX20HK701)

@Kaszaq
Copy link

Kaszaq commented Sep 2, 2019

What I am used to be doing is going through directories in total commander, when in right spot typing "cmd" or "Powershell" to open a cmd line to run some commands. The same way I used to switch between cmd, Powershell or bash. I know these are shells, and this is terminal - however, in the end, all these are "windows where you can type in commands" :).
Need to type anything extra would make terminal work differently to how it currently works in cmd, bash or Powershell.

For the benefit of people looking like me for how this can be worked around for now:
You need to remove "startingDirectory" : "%USERPROFILE%", from profiles.json and then wt will start in the directory you are in. [I have version 0.4.2382.0]

@luscas
Copy link

luscas commented Sep 26, 2020

Run: wt.reg

Windows Registry Editor Version 5.00

[HKEY_CLASSES_ROOT\Directory\Background\shell\wt\command]
@="%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe -d ."

@happyTonakai
Copy link

@akunzai 's solution works for me! Thanks.

@kenblu24
Copy link

I don't see it explicitly mentioned in this thread, but adding/setting "startingDirectory": "", for any particular profile in the settings.json will cause the behavior specified in #3547 i.e. type wt in the explorer bar and start the default terminal profile in the current explorer directory.

hopefully this makes it clearer for people arriving here by Google or whatever.

@aborruso
Copy link

aborruso commented Aug 15, 2021

Hi,
I would like to open Windows Explorer, write wt in the path bar and click ENTER to have my default system opened in that path (it's a debian on WSL2).

But when I run wt I have always as starting path, the user HOME, the ~ that for me is /home/aborruso
I have the same result if I run wt -d .

Below my settings.

How to start windows terminal from current explorer folder, running simply wt?

Thank you

"profiles":
    {
        "defaults":
        {
            "startingDirectory": "."
        },
        "list":
        [
            {
                "commandline": "powershell.exe",
                "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
                "hidden": false,
                "name": "Windows PowerShell"
            },
            {
                "commandline": "cmd.exe",
                "guid": "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}",
                "hidden": false,
                "name": "Prompt dei comandi"
            },
            {
                "commandline": "wsl -d WLinux cd ~; $SHELL --login",
                "guid": "{7f586916-8357-53d4-bb2b-ca96f639898a}",
                "hidden": false,
                "name": "WLinux",
                "source": "Windows.Terminal.Wsl",
                "startingDirectory": "."
            },
            {
                "guid": "{b453ae62-4e3d-5e58-b989-0a998ec441b8}",
                "hidden": false,
                "name": "Azure Cloud Shell",
                "source": "Windows.Terminal.Azure"
            },
            {
                "commandline": "nu.exe",
                "guid": "{2b372ca1-1ee2-403d-a839-6d63077ad871}",
                "hidden": false,
                "name": "Nu Shell"
            }
        ]
    }

image

@DHowett
Copy link
Member

DHowett commented Aug 15, 2021

This is because you have configured your commandline to include cd ~, which totally overrides your starting directory by moving to your Linux home directory no matter what you do.

@aborruso
Copy link

This is because you have configured your commandline to include cd ~, which totally overrides your starting directory by moving to your Linux home directory no matter what you do.

I'm stupid. Solved, thank you

@Zingam
Copy link

Zingam commented Nov 29, 2021

This must be an annoying issue, seeing how many people fail to find it and get's repeated over and over.

:) Maybe Windows could provide an API to solve this issue and it may be even useful to many other applications.

@g-berthiaume
Copy link

I'm here from this issue #11544

I think it's important to make this command tool compatible with the entire command line ecosystem.
In a shell, wt -d . should be replaced by wt . (like for cmd)
In the navigation bar, wt should open the terminal in the current directory (like for cmd)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Settings Issues related to settings and customizability, for console or terminal Issue-Bug It either shouldn't be doing this or needs an investigation. Product-Terminal The new Windows Terminal. Resolution-Won't-Fix We're just really obstinate about this. There's probably a good reason.
Projects
None yet
Development

Successfully merging a pull request may close this issue.