@@ -58,6 +58,54 @@ static Microsoft::Console::TSF::Handle& GetTSFHandle()
58
58
59
59
namespace winrt ::Microsoft::Terminal::Control::implementation
60
60
{
61
+ static void _translatePathInPlace (std::wstring& fullPath, PathTranslationMode translationMode)
62
+ {
63
+ static constexpr wil::zwstring_view s_pathPrefixes[] = {
64
+ {},
65
+ /* WSL */ L" /mnt/" ,
66
+ /* Cygwin */ L" /cygdrive/" ,
67
+ /* MSYS2 */ L" /" ,
68
+ };
69
+
70
+ if (translationMode == PathTranslationMode::None)
71
+ {
72
+ return ;
73
+ }
74
+
75
+ // All of the other path translation modes current result in /-delimited paths
76
+ std::replace (fullPath.begin (), fullPath.end (), L' \\ ' , L' /' );
77
+
78
+ if (fullPath.size () >= 2 && fullPath.at (1 ) == L' :' )
79
+ {
80
+ // C:/foo/bar -> Cc/foo/bar
81
+ fullPath.at (1 ) = til::tolower_ascii (fullPath.at (0 ));
82
+ // Cc/foo/bar -> PREFIXc/foo/bar
83
+ fullPath.replace (0 , 1 , s_pathPrefixes[static_cast <int >(translationMode)]);
84
+ }
85
+ else if (translationMode == PathTranslationMode::WSL)
86
+ {
87
+ // Stripping the UNC name and distribution prefix only applies to WSL.
88
+ static constexpr std::wstring_view wslPathPrefixes[] = { L" //wsl.localhost/" , L" //wsl$/" };
89
+ for (auto prefix : wslPathPrefixes)
90
+ {
91
+ if (til::starts_with (fullPath, prefix))
92
+ {
93
+ if (const auto idx = fullPath.find (L' /' , prefix.size ()); idx != std::wstring::npos)
94
+ {
95
+ // //wsl.localhost/Ubuntu-18.04/foo/bar -> /foo/bar
96
+ fullPath.erase (0 , idx);
97
+ }
98
+ else
99
+ {
100
+ // //wsl.localhost/Ubuntu-18.04 -> /
101
+ fullPath = L" /" ;
102
+ }
103
+ break ;
104
+ }
105
+ }
106
+ }
107
+ }
108
+
61
109
TsfDataProvider::TsfDataProvider (TermControl* termControl) noexcept :
62
110
_termControl{ termControl }
63
111
{
@@ -3233,44 +3281,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation
3233
3281
allPathsString += L" " ;
3234
3282
}
3235
3283
3236
- const auto isWSL = false /* TODO PATH TRANSLATION MODE */ ;
3237
-
3238
- if (isWSL)
3239
- {
3240
- std::replace (fullPath.begin (), fullPath.end (), L' \\ ' , L' /' );
3241
-
3242
- if (fullPath.size () >= 2 && fullPath.at (1 ) == L' :' )
3243
- {
3244
- // C:/foo/bar -> Cc/foo/bar
3245
- fullPath.at (1 ) = til::tolower_ascii (fullPath.at (0 ));
3246
- // Cc/foo/bar -> /mnt/c/foo/bar
3247
- fullPath.replace (0 , 1 , L" /mnt/" );
3248
- }
3249
- else
3250
- {
3251
- static constexpr std::wstring_view wslPathPrefixes[] = { L" //wsl.localhost/" , L" //wsl$/" };
3252
- for (auto prefix : wslPathPrefixes)
3253
- {
3254
- if (til::starts_with (fullPath, prefix))
3255
- {
3256
- if (const auto idx = fullPath.find (L' /' , prefix.size ()); idx != std::wstring::npos)
3257
- {
3258
- // //wsl.localhost/Ubuntu-18.04/foo/bar -> /foo/bar
3259
- fullPath.erase (0 , idx);
3260
- }
3261
- else
3262
- {
3263
- // //wsl.localhost/Ubuntu-18.04 -> /
3264
- fullPath = L" /" ;
3265
- }
3266
- break ;
3267
- }
3268
- }
3269
- }
3270
- }
3284
+ const auto translationMode{ _core.Settings ().PathTranslationMode () };
3285
+ _translatePathInPlace (fullPath, translationMode);
3271
3286
3272
- const auto quotesNeeded = isWSL || fullPath.find (L' ' ) != std::wstring::npos;
3273
- const auto quotesChar = isWSL ? L' \' ' : L' "' ;
3287
+ // All translated paths get quotes, and all strings spaces get quotes; all translated paths get single quotes
3288
+ const auto quotesNeeded = translationMode != PathTranslationMode::None || fullPath.find (L' ' ) != std::wstring::npos;
3289
+ const auto quotesChar = translationMode != PathTranslationMode::None ? L' \' ' : L' "' ;
3274
3290
3275
3291
// Append fullPath and also wrap it in quotes if needed
3276
3292
if (quotesNeeded)
0 commit comments