-
Notifications
You must be signed in to change notification settings - Fork 9k
TerminalControl: Support MinGW path translation style (C:\ -> C:/) #18759
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
Conversation
|
@microsoft-github-policy-service agree |
| pos += cchSingleQuoteEscape; | ||
| } | ||
|
|
||
| if (translationStyle == PathTranslationStyle::MinGW) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is entirely optional, but you could merge this with the following if condition if you wanted to:
if (translationStyle != PathTranslationStyle::MinGW && fullPath.size() >= 2 && fullPath.at(1) == L':')There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for being late in getting back to this.
I thought it was clearer to early-out for the MinGW case to make it obvious that no further processing is required rather than combining the logic with the existing drive handling condition. Readers then know there will be no additional MinGW code further on in the function.
|
Thanks so much for doing this! I'll hold it for a little bit in case you take Leonard's suggestion, but we're otherwise clear to merge :) |
|
/apz run |
|
/azp run |
|
Azure Pipelines successfully started running 1 pipeline(s). |
Documents the new option introduced by microsoft/terminal#18759 Co-authored-by: Adam Butcher <adam@jessamine.uk>
|
@DHowett: This was merged and closed (along with the docs PR) but I didn't see it in a release/prerelease note yet. There is also a "Needs-Tag-Fix" label attached which I'm not sure about. jiyuz comment on #18807 is also releavnt. |
|
Hey, I'm sorry about that. We skipped a whole release cycle to focus on fixing bugs for the current Preview release that is expected to become Stable. :) |
…18759) ## Summary of the Pull Request Support drag-n-drop path translation in the style used by MinGW programs. In particular for usage with shells like `ash` from busybox (https://frippery.org/busybox/). ## Detailed Description of the Pull Request / Additional comments Provides a new option "mingw" for "pathTranslationStyle". Shown as "MinGW" with translation documented as `(C:\ -> C:/)` in the UI. As per the other modes, this translates `\` to `/` but stops there. There is no prefix/drive translation. ## Validation Steps Performed Run using `busybox ash` shell. Dragged directories and files from both local disks and network shares onto terminal. All were appropriately single quoted and had their backslashes replaced with forward slashes. They were directly usable by the `ash` shell. Language files containing the other options have been updated to include the new one. ## PR Checklist - [ ] Closes #xxx - [ ] Tests added/passed - [x] Documentation updated - [Docs PR #849](MicrosoftDocs/terminal#849) - [ ] Schema updated (if necessary) Co-authored-by: Adam Butcher <adam@jessamine.uk> (cherry picked from commit 6682bed) Service-Card-Id: PVTI_lADOAF3p4s4AxadtzgeAsM0 Service-Version: 1.23
|
(I'm an occasional contributor to busybox-w32 and familiar with its codebase, but can't say I know it completely inside out) For future reference, busybox-w32 works fine with either forward or back slashes in paths, and internally it doesn't do any path translations or modification (with few exceptions like It's windows itself which supports forward slashes instead of backslashes, and busybox-w32 relies on this fact to expose some values with forward slashes for convenience and compatibility with portable scripts (like most env vars by default - but not COMSPEC because cmd.exe dislikes it, and the value of $PWD, and possibly few more). So the only issue with "no path translation" in busybox shell in terminal, compared to cmd.exe in terminal, is that the quoting rules are different. busybox ash is a posix shell, so it has posix sh quoting rules, like unix/cygwin/msys2/etc. E.g. So the required-for-busybox-shell thing which this new MinGW mode does is the posix shell quoting. But the main thing it advertises - the back-to-forward shash conversion - is not something busybox-w32 requires or even cares for. EDIT/ADDITION: FYI. |
|
@avih You are right, the quoting is the significant part from the point of view of shell arguments and that is provided by the previously existing posix translation styles. This one just affects how the drive spec is changed (or not changed in this case). There was no existing path translation style that provided the C: drive spec form. I understand that Windows is fine with forward slashes in general (except in certain apps/contexts), and that MinGW and Busybox are (mostly) fine with either path style as a result. The issue with drag-and-drop from explorer was that, by default, it would generate backslashes without hard quoting. These become escape characters and require the user to manually quote the front and back of the path with ' ' to have it make sense. The existing translation modes dropped the colon and potentially added /cygdrive or /mnt prefixes, so would need similar editing. I wanted a mode that would preserve the Windows form but prefer forward slashes. The main reason for the mode was for convenience to prevent the need for manual editing and to allow a dropped path to be emitted in the forward slash style so that it could be used with things like tab-completion in ash without having to cursor around and fix up the backslashes. Try tab completion with a backslash path in ash (whether hard quoted or not). It doesn't work. It does work with the same path with forward slashes. Maybe the name for the style is wrong, or I should have been not being so keen to call out Busybox specifically in the PR summary. But it was for usage in Busybox's ash shell that was my motivating use case (as I tend to use that over any other shell when in Windows), so that's why I mentioned it in the PR. Regarding the name: It was meant to reflect the fact that a GNU system would use forward slashes and that would be the "preferred" path style for MinGW apps (even though they would likely support the backslash alternatives just fine). I had not considered the dropping of paths to be passed to a program that only accepted backslashes as I generally don't run such programs. Thanks for pointing out the issue with cmd.exe though. That is truly strange and I wouldn't have expected that (even from cmd.exe). In fact, I'm not actually sure it's cmd.exe that's doing it. The same hard quoted command line Perhaps we do want a POSIX non-interpolating quote mode though which just does the ' ' quoting and no path translation. But then the option The mode's drop down in the settings UI should probably be updated to be clear on the fact that all the modes will end up quoting the result rather than just performing the translation. Then, if we did have a POSIX hard quote mode it would make it more obvious; |
Yes. I didn't say it's not useful for busybox sh. It is useful. "None" does not work at the shell because it's not quoted correctly, and the other translations (WSL/cygwin/msys2) are quoted correctly, but they also would not work for busybox-w32 (or MinGW), or, more specifically, they wouldn't work for Windows itself. Because busybox-w32 doesn't do any internal paths/arguments/slashes conversions, it's up to Windows itself (and the application which gets executed) to decide what to do with forward slashes in For instance, It's fine for But these do not work in cmd.exe shell, independently (and also not in busybox-w32 shell, for the same reasons): (in the first example the user might expect to open explorer with Explorer will get executed, but it expects its argument to use backslashes, so it will not use the cmd.exe will also run, but the newly-executed cmd.exe parses the command line in such a "special" way, that it will actually identify it as a request to create a directory So obviously this new "MinGW" path translation would work for the first case, but wouldn't work for the other two cases in busybox-w32, and the last case will actually be an intrussive failure - it WILL "succeed" and create a Similarly, there's nothing in current MinGW (MinGW-w64 - which is the headers and a way to build a compiler and tools) which expects or cares about forward slashes, or which does any path translation at any stage at all. MinGW currently also does not include any shell, so the (posix) shell quoting rules are completely irrelevant to "MinGW".
Then you should have invented some name for it, because there's no system which I'm aware of which requires or expects this form, and I do know of systems which will sometimes do unexpected things with it (Windows/MinGW/Busybox-w32). Maybe you could call it after yourself ;) Joking aside, to be fair, the landscape of unix-like things for windows is complex, and its history too, and it's easy to confuse terms, behaviors, and requirements between the various options. So I think the correct thing to do here, assuming the goal is, maybe among others, correctness and usability in busybox-w32 shell:
Do feel free to stop reading here. The rest is a (pretty big) overview and some history lesson, which might help get a clearer picture of the terminology and requirements. Yeah, I got carried away, but I think it's a good overview. Historical and current overview of some unix-like things for windowsClick to expand, at your own riskHere are few things it's worth being aware of, in the context of dragging a path to a shell inside Terminal, and assuming a command takes the form of: COMMAND [PATH|STRING]... [REDIRECTIONS]I.e. COMMAND is the thing to execute, and it takes zero or more independent arguments, where each one is either some arbitrary STRING (like in Each STRING/PATH argument, and redirection PATH, may or may not require quoting - in order for the shell to identify its value correctly. The main path forms are:
Cygwin:
Old/original MinGW (my knowledge is limited, so some details might be incorrect). Its porpose was to allow using gnu compiler to build native win32 applications. Old/original mingw consists of two parts:
Old mingw/msys have not been maintained in any meaningful way for probably more than a decade now, and are rarely used today. Instead, today we have these: Cygwin is still actively maintained, and keeps the same principles detailed above. MinGW-w64:
MSYS2 (I don't follow it closely, feel free to correct inaccuracies):
Busybox (upsrteam):
Busybox-w32
|
Summary of the Pull Request
Support drag-n-drop path translation in the style used by MinGW programs. In particular for usage with shells like
ashfrom busybox (https://frippery.org/busybox/).Detailed Description of the Pull Request / Additional comments
Provides a new option "mingw" for "pathTranslationStyle".
Shown as "MinGW" with translation documented as
(C:\ -> C:/)in the UI.As per the other modes, this translates
\to/but stops there. There is no prefix/drive translation.Validation Steps Performed
Run using
busybox ashshell. Dragged directories and files from both local disks and network shares onto terminal. All were appropriately single quoted and had their backslashes replaced with forward slashes. They were directly usable by theashshell.Language files containing the other options have been updated to include the new one.
PR Checklist