Problem with custom WTHere context menu commands #19912

Closed
opened 2026-01-31 06:57:13 +00:00 by claunia · 15 comments
Owner

Originally created by @vefatica on GitHub (May 20, 2023).

wt -d "c:\" results in

[error 2147942667 (0x8007010b) when launching `d:\tc30\tcc.exe']
Could not access starting directory "c:""

It happens when I use -d "%V" (or "%L") in a Shell\WTHere\command for HKCR\Folder\Background and the folder is a root directory.

I reckon the shell is passing "c:\", and later, somebody (CommandLineToArgvW?) sees the double-quote as being escaped.

Can anything be done?

Originally created by @vefatica on GitHub (May 20, 2023). `wt -d "c:\"` results in ``` [error 2147942667 (0x8007010b) when launching `d:\tc30\tcc.exe'] Could not access starting directory "c:"" ``` It happens when I use `-d "%V"` (or "%L") in a Shell\WTHere\command for HKCR\Folder\Background and the folder is a root directory. I reckon the shell is passing "c:\\", and later, somebody (CommandLineToArgvW?) sees the double-quote as being escaped. Can anything be done?
claunia added the Needs-TriageNeeds-Tag-Fix labels 2026-01-31 06:57:14 +00:00
Author
Owner

@DHowett commented on GitHub (May 20, 2023):

Absolutely! Our typical recommendation to fix this is to use %V\. instead, to avoid the situation where the drive root escapes the closing quote.

@DHowett commented on GitHub (May 20, 2023): Absolutely! Our typical recommendation to fix this is to use `%V\.` instead, to avoid the situation where the drive root escapes the closing quote.
Author
Owner

@vefatica commented on GitHub (May 20, 2023):

That just moves the problem to the case when Explorer doesn't add the backslash, namely, when the directory is not a root directory; then the fix itself adds the offending backslash.

image

image

@vefatica commented on GitHub (May 20, 2023): That just moves the problem to the case when Explorer doesn't add the backslash, namely, when the directory is not a root directory; then the fix itself adds the offending backslash. ![image](https://github.com/microsoft/terminal/assets/61856645/a06e3c84-1ecc-40dd-b5f4-f031c488f559) ![image](https://github.com/microsoft/terminal/assets/61856645/d72c6506-bfb9-4682-ba0b-e15b12e535f5)
Author
Owner

@DHowett commented on GitHub (May 20, 2023):

Not if you do it right!

That period is important.

  • D: plus \. is D:\.
  • D:\ plus \. is D:\\.
  • D:\foo plus \. is D:\foo\.
  • D:\foo\ plus \. is D:\foo\\.

All of those are valid paths that do not cause an escaping problem!

@DHowett commented on GitHub (May 20, 2023): Not if you do it right! That period is important. * `D:` plus `\.` is `D:\.` * `D:\` plus `\.` is `D:\\.` * `D:\foo` plus `\.` is `D:\foo\.` * `D:\foo\` plus `\.` is `D:\foo\\.` All of those are valid paths that do not cause an escaping problem!
Author
Owner

@vefatica commented on GitHub (May 20, 2023):

Oh! I quite simply missed the period.

@vefatica commented on GitHub (May 20, 2023): Oh! I quite simply missed the period.
Author
Owner

@DHowett commented on GitHub (May 20, 2023):

Classic Friday!
Lemme know if that worked out for you :)

@DHowett commented on GitHub (May 20, 2023): Classic Friday! Lemme know if that worked out for you :)
Author
Owner

@vefatica commented on GitHub (May 20, 2023):

Yes, it works; thanks. Off topic but I just saw this thing in DevEnv for the first time. I'd like to know what it is and how to get rid of it!

image

@vefatica commented on GitHub (May 20, 2023): Yes, it works; thanks. Off topic but I just saw this thing in DevEnv for the first time. I'd like to know what it is and how to get rid of it! ![image](https://github.com/microsoft/terminal/assets/61856645/c49d2a04-2c63-4c7f-98f7-a84e36a59728)
Author
Owner

@vefatica commented on GitHub (May 20, 2023):

Never mind. I found it. It's the editor's vertical scroll bar's "map" mode with "Source Overview" on. You've got to dig pretty deep to get at those settings, and I never did that. I wonder why I'm seeing it for the first time today. No big deal; it's off now.

image

@vefatica commented on GitHub (May 20, 2023): Never mind. I found it. It's the editor's vertical scroll bar's "map" mode with "Source Overview" on. You've got to dig pretty deep to get at those settings, and I never did that. I wonder why I'm seeing it for the first time today. No big deal; it's off now. ![image](https://github.com/microsoft/terminal/assets/61856645/131c4adf-8020-4802-b0a3-9f95013efe4b)
Author
Owner

@vefatica commented on GitHub (May 20, 2023):

You know ... -d is not documented as a top-level (not in a sub-command) command line option for either the release or preview version. But it does work to override the configured start-up directory for a profile (default or specified with -p), as well as to set the startup directory for a command-line-specified EXE. Maybe it should be documented.

And the "%V\." trick is very clever but a bit ugly. And it doesn't help in other places, like a plain-old command line (wt -d "c:\directory name\"). Wouldn't it be pretty easy to fix this internally? ... if the argument following "-d" has a double-quote at the end but not one at the beginning ... fix it. Without an internal fix, some guidelines for a "-d" specification seem in order, including a mention of the "%V\." trick.

@vefatica commented on GitHub (May 20, 2023): You know ... `-d` is not documented as a top-level (not in a sub-command) command line option for either the release or preview version. But it does work to override the configured start-up directory for a profile (default or specified with -p), as well as to set the startup directory for a command-line-specified EXE. Maybe it should be documented. And the `"%V\."` trick is very clever but a bit ugly. And it doesn't help in other places, like a plain-old command line (`wt -d "c:\directory name\"`). Wouldn't it be pretty easy to fix this internally? ... if the argument following "-d" has a double-quote at the end but not one at the beginning ... fix it. Without an internal fix, some guidelines for a "-d" specification seem in order, including a mention of the `"%V\."` trick.
Author
Owner

@DHowett commented on GitHub (May 20, 2023):

There's a couple things to unpack here.

-d is an argument to the new-tab and split-pane subcommands. Those are the only two commands that cause new processes to be spawned, and so they're the only two commands that support overriding a starting directory. The starting directory is not a process-wide option.

You can view the help for subcommands by running wt <subcommand-name> --help.


We've attempted to fix command line argument escaping, but every change has drawbacks. Like as not, this is the most consistent way to specify directories whose names contain quotes. Anything else would be a parsing nightmare.

%V\. doesn't help in other places because other places don't use %V. If you append \. anywhere you would generate a starting directory, that is durable and is guaranteed to work everywhere (for all applications, not just Terminal.)

@DHowett commented on GitHub (May 20, 2023): There's a couple things to unpack here. `-d` is an argument to the `new-tab` and `split-pane` subcommands. Those are the only two commands that cause new processes to be spawned, and so they're the only two commands that support overriding a starting directory. The starting directory is not a process-wide option. You can view the help for subcommands by running `wt <subcommand-name> --help`. --- We've attempted to fix command line argument escaping, but every change has drawbacks. Like as not, this is the most consistent way to specify directories whose names contain quotes. Anything else would be a parsing nightmare. `%V\.` doesn't help in other places because other places don't use `%V`. If you append `\.` anywhere you would generate a starting directory, that **is** durable and is guaranteed to work everywhere (for all applications, not just Terminal.)
Author
Owner

@vefatica commented on GitHub (May 21, 2023):

-d also works without a sub-command and not documented as doing so.

For example wt -d d:\ d:\tc24\tcc.exe. That starts WT with one tab, running the specified EXE with d:\ as current directory.

And wt -d d:\ -p CMD starts it with one tab, running the named profile with the specified current directory. Hmmm! -p in this context (no sub-command) isn't documented either.

@vefatica commented on GitHub (May 21, 2023): `-d` also works without a sub-command and not documented as doing so. For example `wt -d d:\ d:\tc24\tcc.exe`. That starts WT with one tab, running the specified EXE with d:\ as current directory. And `wt -d d:\ -p CMD` starts it with one tab, running the named profile with the specified current directory. Hmmm! `-p` in this context (no sub-command) isn't documented either.
Author
Owner

@DHowett commented on GitHub (May 21, 2023):

Funny enough, this is all documented!

If no command is specified, then the command is assumed to be new-tab by default.

@DHowett commented on GitHub (May 21, 2023): Funny enough, this _is_ [all documented](https://learn.microsoft.com/en-us/windows/terminal/command-line-arguments?tabs=windows)! > If no command is specified, then the command is assumed to be `new-tab` by default.
Author
Owner

@DHowett commented on GitHub (May 21, 2023):

As a result, wt appears to support every argument also supported by new-tab. This is a convenience feature so y'all didn't have to learn to run wt nt every time you just wanted to run a command inside Terminal.

@DHowett commented on GitHub (May 21, 2023): As a result, `wt` appears to support every argument also supported by `new-tab`. This is a convenience feature so y'all didn't have to learn to run `wt nt` every time you just wanted to run a command inside Terminal.
Author
Owner

@vefatica commented on GitHub (May 21, 2023):

I found the docs hard to use; enough said.

@vefatica commented on GitHub (May 21, 2023): I found the docs hard to use; enough said.
Author
Owner

@DHowett commented on GitHub (May 21, 2023):

That's great feedback! We would love to do better :)

@DHowett commented on GitHub (May 21, 2023): That's great feedback! We would love to do better :)
Author
Owner

@vefatica commented on GitHub (May 21, 2023):

I am determined to completely figure out the command line syntax, maybe write my own CUI WTHELP (which I'll submit if I do it). So it's likely I'll swamp you with questions. 😁 Here's the first.

How does -w work? I have one instance of WT.EXE (AppPaths) running; it has one tab, named "foo".

image

I issue (anywhere) wt -w foo, expecting a new tab (default nt) in that instance. I get a new instance. What's up with that?

P.S.,

image

@vefatica commented on GitHub (May 21, 2023): I am determined to completely figure out the command line syntax, maybe write my own CUI WTHELP (which I'll submit if I do it). So it's likely I'll swamp you with questions. 😁 Here's the first. How does `-w` work? I have one instance of WT.EXE (AppPaths) running; it has one tab, named "foo". ![image](https://github.com/microsoft/terminal/assets/61856645/0f305f02-e45d-4ccd-8c35-05c12506c112) I issue (anywhere) `wt -w foo`, expecting a new tab (default nt) in that instance. I get a new instance. What's up with that? P.S., ![image](https://github.com/microsoft/terminal/assets/61856645/15e895c8-1cf8-4d73-bb1f-b446f9eb82b8)
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/terminal#19912