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

Add a new (advanced) profile setting, pathTranslationStyle #18195

Merged
merged 6 commits into from
Nov 15, 2024

Conversation

DHowett
Copy link
Member

@DHowett DHowett commented Nov 14, 2024

pathTranslationStyle has four options:

  • none: Do no translation
  • wsl: Translate C:\ to /mnt/c and \\wsl$\Foo\bar to /bar
  • cygwin: Translate C:\ to /cygdrive/c
  • msys2: Translate C:\ to /c

It is intended as a broadly-supported replacement for us checking the
source every time the user drops a path.

We no longer need to push the source name all the way down to the control.

I am hesitant to commit to using other folks' product names in our settings model,
however, these are almost certainly more recognizable than whatever other weird
names we could come up with.

The Git Bash fragment extension profile could conceivably use pathTranslationStyle
msys2 to make sure drag/dropped paths look right.

@DHowett
Copy link
Member Author

DHowett commented Nov 14, 2024

Thoughts:

  • Is it more of a pathTranslationStyle (EDIT: I chose this one!)? pathTranslation?
  • Should we come up with up different value names like mnt cygdrive and root? Or posix-mnt, posix-cygdrive, posix-root?
  • Ubuntu (Canonical) can also set this in their fragment.

Notes for later:

I need to add PathTranslationMode(WSL) to the WslDistroGenerator to close the loop.

This comment has been minimized.

@DHowett
Copy link
Member Author

DHowett commented Nov 14, 2024

This does not preclude us shipping custom mapping support in the future. It would make it more annoying (we could set pathTranslationMode to an object, or to custom and add another setting)

This comment has been minimized.

@dscho
Copy link
Member

dscho commented Nov 14, 2024

I like pathTranslationStyle, and yes, I think names like cygwin, wsl and msys2 are optimal: they are easily understood, especially when the key suggests that we imitate the style of those products here.

And absolutely: I will use this in the Git Bash profile that is installed by Git for Windows' installer (opt-in). Great work @DHowett!

@DHowett DHowett force-pushed the dev/duhowett/honeywell-ptm branch from fc90723 to 9135943 Compare November 14, 2024 17:02

This comment has been minimized.

`pathTranslationStyle` has four options:

- `none`: Do no translation
- `wsl`: Translate `C:\` to `/mnt/c` and `\\wsl$\Foo\bar` to `/bar`
- `cygwin`: Translate `C:\` to `/cygdrive/c`
- `msys2`: Translate `C:\` to `/c`

It is intended as a broadly-supported replacement for us checking the
source every time the user drops a path.
@DHowett DHowett changed the title Add a new (advanced) profile setting, pathTranslationMode Add a new (advanced) profile setting, pathTranslationStyle Nov 14, 2024
@DHowett DHowett force-pushed the dev/duhowett/honeywell-ptm branch from 9135943 to a596124 Compare November 14, 2024 17:53
Copy link
Member

@lhecker lhecker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

neat

Comment on lines +1980 to +1991
<value>WSL (C:\ -> /mnt/c)</value>
<comment>{Locked="WSL","C:\","/mnt/c"} An option to choose from for the "path translation" setting.</comment>
</data>
<data name="Profile_PathTranslationStyleCygwin.Content" xml:space="preserve">
<value>Cygwin (C:\ -> /cygdrive/c)</value>
<comment>{Locked="Cygwin","C:\","/cygdrive/c"} An option to choose from for the "path translation" setting.</comment>
</data>
<data name="Profile_PathTranslationStyleMsys2.Content" xml:space="preserve">
<value>MSYS2 (C:\ -> /c)</value>
<comment>{Locked="MSYS2","C:\","/c"} An option to choose from for the "path translation" setting.</comment>
</data>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love the examples!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just realized we could use a proper → arrow here. Pasting it into a textbox in our current SUI looks great, so maybe it would work?

image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh i didn't understand this until now. thanks, i should do this

{
// Stripping the UNC name and distribution prefix only applies to WSL.
static constexpr std::wstring_view wslPathPrefixes[] = { L"//wsl.localhost/", L"//wsl$/" };
for (auto prefix : wslPathPrefixes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
for (auto prefix : wslPathPrefixes)
for (const auto prefix : wslPathPrefixes)

@carlos-zamora
Copy link
Member

Oh! Don't forget the schema!

DHowett and others added 2 commits November 14, 2024 17:46
…l-ptm

# Conflicts:
#	src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw
@DHowett DHowett force-pushed the dev/duhowett/honeywell-ptm branch from b59067b to 5960ef3 Compare November 15, 2024 23:24
@DHowett DHowett enabled auto-merge (squash) November 15, 2024 23:47
@DHowett DHowett merged commit 0689067 into main Nov 15, 2024
18 of 20 checks passed
@DHowett DHowett deleted the dev/duhowett/honeywell-ptm branch November 15, 2024 23:55
DHowett added a commit that referenced this pull request Nov 16, 2024
In #18195, we introduced a real `pathTranslationStyle` setting.

I'm not backporting that whole thing.
DHowett added a commit that referenced this pull request Nov 18, 2024
In #18195, we introduced a real `pathTranslationStyle` setting.

I'm not backporting that whole thing.
DHowett added a commit that referenced this pull request Nov 18, 2024
In #18195, we introduced a real `pathTranslationStyle` setting.

I'm not backporting that whole thing.

(cherry picked from commit e476dd2)
Service-Card-Id: PVTI_lADOAF3p4s4AmhmszgU2fsY
Service-Version: 1.21
DHowett pushed a commit that referenced this pull request Nov 23, 2024
When file/folder is dropped to the terminal, its path is translated and
quoted with a pair of single quotes if necessary.

However, the terminal control does not escape single quotes (allowed in
the Win32 subsystem) that need escapes when translated.

On the translation styles other than `"none"` (note: all other
translation styles are currently intended for the POSIX shell), it
causes incorrect path to be pasted when the path contains one or more
single quotes (see #18006 for an example).

With this commit, the terminal control escapes a single quote with a
valid escape sequence `'\''` (finish quote, print a single quote then
begin quote again) when the path translation is required.

## History

### v1 → v2

* Changed escape sequence from `'"'"'` to much shorter `'\''`.
* Reflected comments by the reviewer.

### v2 → v3

* Overhaul after addition of multiple path translation styles (not just
WSL but Cygwin and MSYS).
* More clarification both in the code and in the commit message.

### v3 → v4 (current)

* Minor clarification both in the code and in the commit message.

## References and Relevant Issues

* #18006
* #16214
* #18195

## Detailed Description of the Pull Request / Additional comments

This is a follow-up of #16214 and #18195, fixing #18006.

Closes #18006
DHowett pushed a commit that referenced this pull request Nov 25, 2024
When file/folder is dropped to the terminal, its path is translated and
quoted with a pair of single quotes if necessary.

However, the terminal control does not escape single quotes (allowed in
the Win32 subsystem) that need escapes when translated.

On the translation styles other than `"none"` (note: all other
translation styles are currently intended for the POSIX shell), it
causes incorrect path to be pasted when the path contains one or more
single quotes (see #18006 for an example).

With this commit, the terminal control escapes a single quote with a
valid escape sequence `'\''` (finish quote, print a single quote then
begin quote again) when the path translation is required.

* Changed escape sequence from `'"'"'` to much shorter `'\''`.
* Reflected comments by the reviewer.

* Overhaul after addition of multiple path translation styles (not just
WSL but Cygwin and MSYS).
* More clarification both in the code and in the commit message.

* Minor clarification both in the code and in the commit message.

* #18006
* #16214
* #18195

This is a follow-up of #16214 and #18195, fixing #18006.

Closes #18006

(cherry picked from commit ae90d52)
Service-Card-Id: PVTI_lADOAF3p4s4AmhmszgVEvdY
Service-Version: 1.21
DHowett pushed a commit that referenced this pull request Nov 25, 2024
When file/folder is dropped to the terminal, its path is translated and
quoted with a pair of single quotes if necessary.

However, the terminal control does not escape single quotes (allowed in
the Win32 subsystem) that need escapes when translated.

On the translation styles other than `"none"` (note: all other
translation styles are currently intended for the POSIX shell), it
causes incorrect path to be pasted when the path contains one or more
single quotes (see #18006 for an example).

With this commit, the terminal control escapes a single quote with a
valid escape sequence `'\''` (finish quote, print a single quote then
begin quote again) when the path translation is required.

* Changed escape sequence from `'"'"'` to much shorter `'\''`.
* Reflected comments by the reviewer.

* Overhaul after addition of multiple path translation styles (not just
WSL but Cygwin and MSYS).
* More clarification both in the code and in the commit message.

* Minor clarification both in the code and in the commit message.

* #18006
* #16214
* #18195

This is a follow-up of #16214 and #18195, fixing #18006.

Closes #18006

(cherry picked from commit ae90d52)
Service-Card-Id: PVTI_lADOAF3p4s4AmhmQzgVEvdU
Service-Version: 1.22
DHowett added a commit that referenced this pull request Feb 3, 2025
`pathTranslationStyle` has four options:

- `none`: Do no translation
- `wsl`: Translate `C:\` to `/mnt/c` and `\\wsl$\Foo\bar` to `/bar`
- `cygwin`: Translate `C:\` to `/cygdrive/c`
- `msys2`: Translate `C:\` to `/c`

It is intended as a broadly-supported replacement for us checking the
source every time the user drops a path.

We no longer need to push the source name all the way down to the
control.

I am hesitant to commit to using other folks' product names in our
settings model,
however, these are almost certainly more recognizable than whatever
other weird
names we could come up with.

The Git Bash fragment extension profile could conceivably use
`pathTranslationStyle`
`msys2` to make sure drag/dropped paths look right.

(cherry picked from commit 0689067)
Service-Card-Id: PVTI_lADOAF3p4s4AmhmQzgW9l6A
Service-Version: 1.22
DHowett pushed a commit that referenced this pull request Feb 3, 2025
When file/folder is dropped to the terminal, its path is translated and
quoted with a pair of single quotes if necessary.

However, the terminal control does not escape single quotes (allowed in
the Win32 subsystem) that need escapes when translated.

On the translation styles other than `"none"` (note: all other
translation styles are currently intended for the POSIX shell), it
causes incorrect path to be pasted when the path contains one or more
single quotes (see #18006 for an example).

With this commit, the terminal control escapes a single quote with a
valid escape sequence `'\''` (finish quote, print a single quote then
begin quote again) when the path translation is required.

* Changed escape sequence from `'"'"'` to much shorter `'\''`.
* Reflected comments by the reviewer.

* Overhaul after addition of multiple path translation styles (not just
WSL but Cygwin and MSYS).
* More clarification both in the code and in the commit message.

* Minor clarification both in the code and in the commit message.

* #18006
* #16214
* #18195

This is a follow-up of #16214 and #18195, fixing #18006.

Closes #18006

Supersedes 7878728

(cherry picked from commit ae90d52)
Service-Card-Id: PVTI_lADOAF3p4s4AmhmQzgVEvdU
Service-Version: 1.22
DHowett added a commit that referenced this pull request Feb 3, 2025
`pathTranslationStyle` has four options:

- `none`: Do no translation
- `wsl`: Translate `C:\` to `/mnt/c` and `\\wsl$\Foo\bar` to `/bar`
- `cygwin`: Translate `C:\` to `/cygdrive/c`
- `msys2`: Translate `C:\` to `/c`

It is intended as a broadly-supported replacement for us checking the
source every time the user drops a path.

We no longer need to push the source name all the way down to the
control.

I am hesitant to commit to using other folks' product names in our
settings model,
however, these are almost certainly more recognizable than whatever
other weird
names we could come up with.

The Git Bash fragment extension profile could conceivably use
`pathTranslationStyle`
`msys2` to make sure drag/dropped paths look right.

(cherry picked from commit 0689067)
Service-Card-Id: PVTI_lADOAF3p4s4AmhmQzgW9l6A
Service-Version: 1.22
DHowett pushed a commit that referenced this pull request Feb 3, 2025
When file/folder is dropped to the terminal, its path is translated and
quoted with a pair of single quotes if necessary.

However, the terminal control does not escape single quotes (allowed in
the Win32 subsystem) that need escapes when translated.

On the translation styles other than `"none"` (note: all other
translation styles are currently intended for the POSIX shell), it
causes incorrect path to be pasted when the path contains one or more
single quotes (see #18006 for an example).

With this commit, the terminal control escapes a single quote with a
valid escape sequence `'\''` (finish quote, print a single quote then
begin quote again) when the path translation is required.

* Changed escape sequence from `'"'"'` to much shorter `'\''`.
* Reflected comments by the reviewer.

* Overhaul after addition of multiple path translation styles (not just
WSL but Cygwin and MSYS).
* More clarification both in the code and in the commit message.

* Minor clarification both in the code and in the commit message.

* #18006
* #16214
* #18195

This is a follow-up of #16214 and #18195, fixing #18006.

Closes #18006

Supersedes 7878728

(cherry picked from commit ae90d52)
Service-Card-Id: PVTI_lADOAF3p4s4AmhmQzgVEvdU
Service-Version: 1.22
@jeremyd2019
Copy link

jeremyd2019 commented Feb 6, 2025

FYI, on Cygwin (and MSYS2) the cygdrive prefix can be changed in /etc/fstab. In fact, this is what MSYS2 does to make it / instead of /cygdrive. In order to let 3rd party code not have to care about this, Cygwin has the fixed path (symlink to the configured cygdrive prefix) /proc/cygdrive, which also exists and works in MSYS2. (So, you could have one cygwin-ish path translation mode that prepends /proc/cygdrive/ instead of one that prepends / and one that prepends /cygdrive, and doesn't know if the user configured something else.) See https://cygwin.com/cygwin-ug-net/using.html#cygdrive

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Cherry Picked
Development

Successfully merging this pull request may close these issues.

5 participants