@@ -107,9 +107,9 @@ bool FileExists(const wchar_t * filePath)
107
107
108
108
void StartCmder (std::wstring path = L" " , bool is_single_mode = false , std::wstring taskName = L" " , std::wstring title = L" " , std::wstring iconPath = L" " , std::wstring cfgRoot = L" " , bool use_user_cfg = true , std::wstring conemu_args = L" " )
109
109
{
110
- #if USE_TASKBAR_API
111
- wchar_t appId[MAX_PATH] = { 0 };
112
- #endif
110
+ #if USE_TASKBAR_API
111
+ wchar_t appId[MAX_PATH] = { 0 };
112
+ #endif
113
113
wchar_t exeDir[MAX_PATH] = { 0 };
114
114
wchar_t icoPath[MAX_PATH] = { 0 };
115
115
wchar_t cfgPath[MAX_PATH] = { 0 };
@@ -131,8 +131,17 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
131
131
wchar_t windowsTerminalDir[MAX_PATH] = { 0 };
132
132
wchar_t conEmuDir[MAX_PATH] = { 0 };
133
133
wchar_t winDir[MAX_PATH] = { 0 };
134
- wchar_t emulatorPath[MAX_PATH] = { 0 };
135
-
134
+ wchar_t vendorDir[MAX_PATH] = { 0 };
135
+ wchar_t initCmd[MAX_PATH] = { 0 };
136
+ wchar_t initPowerShell[MAX_PATH] = { 0 };
137
+ wchar_t initBash[MAX_PATH] = { 0 };
138
+ wchar_t initMintty[MAX_PATH] = { 0 };
139
+ wchar_t vendoredGit[MAX_PATH] = { 0 };
140
+ wchar_t amdx64Git[MAX_PATH] = { 0 };
141
+ wchar_t x86Git[MAX_PATH] = { 0 };
142
+ wchar_t programFiles[MAX_PATH] = { 0 };
143
+ wchar_t programFilesX86[MAX_PATH] = { 0 };
144
+ wchar_t minTTYPath[MAX_PATH] = { 0 };
136
145
137
146
std::wstring cmderStart = path;
138
147
std::wstring cmderTask = taskName;
@@ -144,9 +153,9 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
144
153
145
154
GetModuleFileName (NULL , exeDir, sizeof (exeDir));
146
155
147
- #if USE_TASKBAR_API
148
- wcscpy_s (appId, exeDir);
149
- #endif
156
+ #if USE_TASKBAR_API
157
+ wcscpy_s (appId, exeDir);
158
+ #endif
150
159
151
160
PathRemoveFileSpec (exeDir);
152
161
@@ -255,8 +264,9 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
255
264
}
256
265
}
257
266
258
- PathCombine (windowsTerminalDir, exeDir, L" vendor\\ windows-terminal" );
259
- PathCombine (conEmuDir, exeDir, L" vendor\\ conemu-maximus5" );
267
+ PathCombine (vendorDir, exeDir, L" vendor" );
268
+ PathCombine (windowsTerminalDir, vendorDir, L" windows-terminal" );
269
+ PathCombine (conEmuDir, vendorDir, L" conemu-maximus5" );
260
270
GetEnvironmentVariable (L" WINDIR" , winDir, MAX_PATH);
261
271
262
272
if (PathFileExists (windowsTerminalDir))
@@ -319,7 +329,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
319
329
{
320
330
if (!CopyFile (cpuCfgPath, cfgPath, FALSE ))
321
331
{
322
- if (PathFileExists (windowsTerminalDir)) {
332
+ if (PathFileExists (windowsTerminalDir)) {
323
333
MessageBox (NULL ,
324
334
(GetLastError () == ERROR_ACCESS_DENIED)
325
335
? L" Failed to copy config/windows_terminal_%COMPUTERNAME%_settings.json file to vendor/windows-terminal/settings/settings.json! Access Denied."
@@ -346,7 +356,8 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
346
356
{
347
357
if (!CopyFile (cfgPath, userCfgPath, FALSE ))
348
358
{
349
- if (PathFileExists (windowsTerminalDir)) {
359
+ if (PathFileExists (windowsTerminalDir))
360
+ {
350
361
MessageBox (NULL ,
351
362
(GetLastError () == ERROR_ACCESS_DENIED)
352
363
? L" Failed to copy vendor/windows-terminal/settings/settings.json file to config/windows_terminal_settings.json! Access Denied."
@@ -367,7 +378,8 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
367
378
{
368
379
if (!CopyFile (userCfgPath, cfgPath, FALSE ))
369
380
{
370
- if (PathFileExists (windowsTerminalDir)) {
381
+ if (PathFileExists (windowsTerminalDir))
382
+ {
371
383
MessageBox (NULL ,
372
384
(GetLastError () == ERROR_ACCESS_DENIED)
373
385
? L" Failed to copy config/user_windows_terminal_settings.json file to vendor/windows-terminal/settings/settings.json! Access Denied."
@@ -395,7 +407,8 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
395
407
{
396
408
if (!CopyFile (cfgPath, userCfgPath, FALSE ))
397
409
{
398
- if (PathFileExists (windowsTerminalDir)) {
410
+ if (PathFileExists (windowsTerminalDir))
411
+ {
399
412
MessageBox (NULL ,
400
413
(GetLastError () == ERROR_ACCESS_DENIED)
401
414
? L" Failed to copy vendor/windows-terminal/settings/settings.json file to config/user_windows_terminal_settings.json! Access Denied."
@@ -415,7 +428,8 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
415
428
{
416
429
if (!CopyFile (defaultCfgPath, cfgPath, FALSE ))
417
430
{
418
- if (PathFileExists (windowsTerminalDir)) {
431
+ if (PathFileExists (windowsTerminalDir))
432
+ {
419
433
MessageBox (NULL ,
420
434
(GetLastError () == ERROR_ACCESS_DENIED)
421
435
? L" Failed to copy vendor/windows-terminal_default_settings_settings.json file to vendor/windows-terminal/settings/settings.json! Access Denied."
@@ -437,7 +451,7 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
437
451
{
438
452
MessageBox (NULL ,
439
453
(GetLastError () == ERROR_ACCESS_DENIED)
440
- ? L" Failed to copy vendor/ConEmu.xml.default file to vendor/conemu-maximus5/ConEmu.xml! Access Denied."
454
+ ? L" Failed to copy vendor/ConEmu.xml.default file to vendor/conemu-maximus5/ConEmu.xml! Access Denied."
441
455
: L" Failed to copy vendor/ConEmu.xml.default file to vendor/conemu-maximus5/ConEmu.xml!" , MB_TITLE, MB_ICONSTOP);
442
456
exit (1 );
443
457
}
@@ -446,7 +460,8 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
446
460
{
447
461
if (!CopyFile (cfgPath, userCfgPath, FALSE ))
448
462
{
449
- if (PathFileExists (windowsTerminalDir)) {
463
+ if (PathFileExists (windowsTerminalDir))
464
+ {
450
465
MessageBox (NULL ,
451
466
(GetLastError () == ERROR_ACCESS_DENIED)
452
467
? L" Failed to copy vendor/windows-terminal/settings/settings.json file to config/user_windows_terminal_settings_settings.json! Access Denied."
@@ -469,7 +484,8 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
469
484
{
470
485
if ( ! CopyFile (defaultCfgPath, userCfgPath, FALSE ))
471
486
{
472
- if (PathFileExists (windowsTerminalDir)) {
487
+ if (PathFileExists (windowsTerminalDir))
488
+ {
473
489
MessageBox (NULL ,
474
490
(GetLastError () == ERROR_ACCESS_DENIED)
475
491
? L" Failed to copy vendor/windows-terminal_default_settings_settings.json file to [user specified path]/config/user_windows_terminal_settings.json! Access Denied."
@@ -488,22 +504,50 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
488
504
PathCombine (userConEmuCfgPath, userConfigDirPath, L" user-ConEmu.xml" );
489
505
}
490
506
507
+ GetEnvironmentVariable (L" ProgramFiles" , programFiles, MAX_PATH);
508
+ GetEnvironmentVariable (L" ProgramFiles(x86)" , programFilesX86, MAX_PATH);
509
+
510
+ PathCombine (vendoredGit, vendorDir, L" git-for-windows" );
511
+ PathCombine (amdx64Git, programFiles, L" Git" );
512
+ PathCombine (x86Git, programFilesX86, L" Git" );
513
+
491
514
SYSTEM_INFO sysInfo;
492
515
GetNativeSystemInfo (&sysInfo);
493
- if (PathFileExists (windowsTerminalDir)) {
516
+ if (PathFileExists (windowsTerminalDir))
517
+ {
494
518
PathCombine (terminalPath, exeDir, L" vendor\\ windows-terminal\\ WindowsTerminal.exe" );
495
519
}
496
520
else if (PathFileExists (conEmuDir))
497
521
{
522
+ swprintf_s (args, L" %s /Icon \" %s\" " , args, icoPath);
523
+ swprintf_s (args, L" %s /title \" %s\" " , args, cmderTitle.c_str ());
498
524
PathCombine (terminalPath, exeDir, L" vendor\\ conemu-maximus5\\ ConEmu64.exe" );
499
525
}
500
526
else
501
527
{
502
528
PathCombine (terminalPath, winDir, L" system32\\ cmd.exe" );
503
- }
504
529
505
- if (!PathFileExists (windowsTerminalDir)) {
506
- swprintf_s (args, L" %s /Icon \" %s\" " , args, icoPath);
530
+ if (streqi (cmderTask.c_str (), L" powershell" ))
531
+ {
532
+ PathCombine (terminalPath, winDir, L" System32\\ WindowsPowerShell\\ v1.0\\ powershell.exe" );
533
+ }
534
+ /*
535
+ else if (streqi(cmderTask.c_str(), L"mintty"))
536
+ {
537
+ if (PathFileExists(vendoredGit))
538
+ {
539
+ PathCombine(terminalPath, vendoredGit, L"git-bash.exe");
540
+ }
541
+ else if (PathFileExists(amdx64Git))
542
+ {
543
+ PathCombine(terminalPath, amdx64Git, L"git-bash.exe");
544
+ }
545
+ else if (PathFileExists(x86Git))
546
+ {
547
+ PathCombine(terminalPath, x86Git, L"git-bash.exe");
548
+ }
549
+ }
550
+ */
507
551
}
508
552
509
553
if (!streqi (cmderStart.c_str (), L" " ))
@@ -524,13 +568,6 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
524
568
}
525
569
}
526
570
527
- if (!streqi (cmderTitle.c_str (), L" " ))
528
- {
529
- if (!PathFileExists (windowsTerminalDir)) {
530
- swprintf_s (args, L" %s /title \" %s\" " , args, cmderTitle.c_str ());
531
- }
532
- }
533
-
534
571
if (cfgRoot.length () != 0 )
535
572
{
536
573
if (!PathFileExists (windowsTerminalDir)) {
@@ -546,6 +583,11 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
546
583
// The `/run` arg and its value MUST be the last arg of ConEmu
547
584
// see : https://conemu.github.io/en/ConEmuArgs.html
548
585
// > This must be the last used switch (excepting -new_console and -cur_console)
586
+ PathCombine (initCmd, vendorDir, L" init.bat" );
587
+ PathCombine (initPowerShell, vendorDir, L" profile.ps1" );
588
+ PathCombine (initBash, vendorDir, L" start_git_bash.cmd" );
589
+ PathCombine (initMintty, vendorDir, L" start_git_mintty.cmd" );
590
+
549
591
if (!streqi (cmderTask.c_str (), L" " ))
550
592
{
551
593
if (PathFileExists (windowsTerminalDir)) {
@@ -557,7 +599,22 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
557
599
}
558
600
else
559
601
{
560
- swprintf_s (args, L" %s %s" , args, cmderTask.c_str ());
602
+ if (streqi (cmderTask.c_str (), L" powershell" ))
603
+ {
604
+ swprintf_s (args, L" %s -ExecutionPolicy Bypass -NoLogo -NoProfile -NoExit -Command \" Invoke-Expression 'Import-Module ''%s'''\" " , args, initPowerShell);
605
+ }
606
+ else if (streqi (cmderTask.c_str (), L" bash" ))
607
+ {
608
+ swprintf_s (args, L" %s /c \" %s\" " , args, initBash);
609
+ }
610
+ else if (streqi (cmderTask.c_str (), L" mintty" ))
611
+ {
612
+ swprintf_s (args, L" %s /c \" %s\" " , args, initMintty);
613
+ }
614
+ else if (streqi (cmderTask.c_str (), L" cmder" ))
615
+ {
616
+ swprintf_s (args, L" %s /k \" %s\" " , args, initCmd);
617
+ }
561
618
}
562
619
}
563
620
@@ -568,23 +625,42 @@ void StartCmder(std::wstring path = L"", bool is_single_mode = false, std::wstr
568
625
SetEnvironmentVariable (L" CMDER_USER_BIN" , userBinDirPath);
569
626
}
570
627
628
+ // Try to find m'intty.exe' so ConEmu can launch using %MINTTY_EXE% in external Git for Cmder Mini.
629
+ // See: https://github.com/Maximus5/ConEmu/issues/2559 for why this is commented.
630
+
631
+ /*
632
+ if (PathFileExists(vendoredGit))
633
+ {
634
+ PathCombine(minTTYPath, vendoredGit, L"usr\\bin\\mintty.exe");
635
+ SetEnvironmentVariable(L"MINTTY_EXE", minTTYPath);
636
+ }
637
+ else if (PathFileExists(amdx64Git))
638
+ {
639
+ PathCombine(minTTYPath, amdx64Git, L"usr\\bin\\mintty.exe");
640
+ SetEnvironmentVariable(L"MINTTY_EXE", minTTYPath);
641
+ }
642
+ else if (PathFileExists(x86Git))
643
+ {
644
+ PathCombine(minTTYPath, x86Git, L"usr\\bin\\mintty.exe");
645
+ SetEnvironmentVariable(L"MINTTY_EXE", minTTYPath);
646
+ }
647
+ */
648
+
571
649
// Ensure EnvironmentVariables are propagated.
572
650
573
651
STARTUPINFO si = { 0 };
574
652
575
653
si.cb = sizeof (STARTUPINFO);
576
- #if USE_TASKBAR_API
577
- si.lpTitle = appId;
578
- si.dwFlags = STARTF_TITLEISAPPID;
579
- #endif
654
+ #if USE_TASKBAR_API
655
+ si.lpTitle = appId;
656
+ si.dwFlags = STARTF_TITLEISAPPID;
657
+ #endif
580
658
PROCESS_INFORMATION pi ;
581
-
582
- // MessageBox(NULL, terminalPath, _T("Error"), MB_OK);
583
- // MessageBox(NULL, args, _T("Error"), MB_OK);
584
659
585
660
if (!CreateProcess (terminalPath, args, NULL , NULL , false , 0 , NULL , NULL , &si, &pi ))
586
661
{
587
- if (PathFileExists (windowsTerminalDir)) {
662
+ if (PathFileExists (windowsTerminalDir))
663
+ {
588
664
MessageBox (NULL , _T (" Unable to create the Windows Terminal process!" ), _T (" Error" ), MB_OK);
589
665
}
590
666
else if (PathFileExists (conEmuDir))
@@ -729,15 +805,13 @@ cmderOptions GetOption()
729
805
wchar_t conEmuDir[MAX_PATH] = { 0 };
730
806
wchar_t vendorDir[MAX_PATH] = { 0 };
731
807
wchar_t exeDir[MAX_PATH] = { 0 };
732
- wchar_t cmdInit[MAX_PATH] = { 0 };
733
808
734
809
GetModuleFileName (NULL , exeDir, sizeof (exeDir));
735
810
PathRemoveFileSpec (exeDir);
736
811
737
812
PathCombine (vendorDir, exeDir, L" vendor" );
738
813
PathCombine (windowsTerminalDir, vendorDir, L" windows-terminal" );
739
814
PathCombine (conEmuDir, vendorDir, L" ConEmu-Maximus5" );
740
- PathCombine (cmdInit, vendorDir, L" init.bat" );
741
815
742
816
szArgList = CommandLineToArgvW (GetCommandLine (), &argCount);
743
817
@@ -868,14 +942,11 @@ cmderOptions GetOption()
868
942
cmderOptions.error = true ;
869
943
}
870
944
}
871
-
872
945
}
873
946
874
- if (!PathFileExists (windowsTerminalDir) && !PathFileExists (conEmuDir))
947
+ if (!PathFileExists (windowsTerminalDir) && !PathFileExists (conEmuDir) && streqi (cmderOptions. cmderTask . c_str (), L" " ) )
875
948
{
876
- cmderOptions.cmderTask = L" /k \" " ;
877
- cmderOptions.cmderTask += cmdInit;
878
- cmderOptions.cmderTask += L" \" " ;
949
+ cmderOptions.cmderTask = L" cmder" ;
879
950
}
880
951
881
952
if (cmderOptions.error == true )
@@ -909,13 +980,12 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
909
980
910
981
GetModuleFileName (NULL , exeDir, sizeof (exeDir));
911
982
PathRemoveFileSpec (exeDir);
912
-
913
- PathCombine (windowsTerminalDir, exeDir, L" vendor\\ windows-terminal" );
983
+ PathCombine (windowsTerminalDir, exeDir, L" vendor\\ windows-terminal" );
914
984
915
985
if (cmderOptions.registerApp == true )
916
986
{
917
- if (PathFileExists (windowsTerminalDir))
918
- {
987
+ if (PathFileExists (windowsTerminalDir))
988
+ {
919
989
RegisterShellMenu (cmderOptions.cmderRegScope , SHELL_MENU_REGISTRY_PATH_BACKGROUND, cmderOptions.cmderCfgRoot , cmderOptions.cmderSingle );
920
990
RegisterShellMenu (cmderOptions.cmderRegScope , SHELL_MENU_REGISTRY_PATH_LISTITEM, cmderOptions.cmderCfgRoot , cmderOptions.cmderSingle );
921
991
RegisterShellMenu (cmderOptions.cmderRegScope , SHELL_MENU_REGISTRY_DRIVE_PATH_BACKGROUND, cmderOptions.cmderCfgRoot , cmderOptions.cmderSingle );
@@ -946,4 +1016,4 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
946
1016
}
947
1017
948
1018
return 0 ;
949
- }
1019
+ }
0 commit comments