11using System . Diagnostics ;
2+ using System . Text ;
23using Hypr . Configuration ;
34using Microsoft . Extensions . Logging ;
45
@@ -54,30 +55,7 @@ public bool Open(string workingDirectory, TerminalMode mode, string? initCommand
5455 {
5556 try
5657 {
57- var psi = new ProcessStartInfo
58- {
59- FileName = "wt" ,
60- UseShellExecute = false
61- } ;
62-
63- var hasInitCommand = ! string . IsNullOrEmpty ( initCommand ) ;
64-
65- if ( hasInitCommand )
66- {
67- psi . ArgumentList . Add ( mode == TerminalMode . Tab ? "new-tab" : "new-window" ) ;
68- psi . ArgumentList . Add ( "-d" ) ;
69- psi . ArgumentList . Add ( workingDirectory ) ;
70- psi . ArgumentList . Add ( "powershell" ) ;
71- psi . ArgumentList . Add ( "-NoExit" ) ;
72- psi . ArgumentList . Add ( "-Command" ) ;
73- psi . ArgumentList . Add ( initCommand ! ) ;
74- }
75- else
76- {
77- psi . ArgumentList . Add ( mode == TerminalMode . Tab ? "new-tab" : "new-window" ) ;
78- psi . ArgumentList . Add ( "-d" ) ;
79- psi . ArgumentList . Add ( workingDirectory ) ;
80- }
58+ var psi = CreateStartInfo ( workingDirectory , mode , initCommand ) ;
8159
8260 Process . Start ( psi ) ;
8361 _logger . LogInformation ( "Opened {Path} in Windows Terminal ({Mode})" , workingDirectory , mode ) ;
@@ -89,4 +67,33 @@ public bool Open(string workingDirectory, TerminalMode mode, string? initCommand
8967 return false ;
9068 }
9169 }
70+
71+ internal static ProcessStartInfo CreateStartInfo ( string workingDirectory , TerminalMode mode , string ? initCommand = null )
72+ {
73+ var psi = new ProcessStartInfo
74+ {
75+ FileName = "wt" ,
76+ UseShellExecute = false
77+ } ;
78+
79+ if ( mode == TerminalMode . Window )
80+ {
81+ psi . ArgumentList . Add ( "-w" ) ;
82+ psi . ArgumentList . Add ( "new" ) ;
83+ }
84+
85+ psi . ArgumentList . Add ( "new-tab" ) ;
86+ psi . ArgumentList . Add ( "-d" ) ;
87+ psi . ArgumentList . Add ( workingDirectory ) ;
88+
89+ if ( ! string . IsNullOrWhiteSpace ( initCommand ) )
90+ {
91+ psi . ArgumentList . Add ( "powershell" ) ;
92+ psi . ArgumentList . Add ( "-NoExit" ) ;
93+ psi . ArgumentList . Add ( "-EncodedCommand" ) ;
94+ psi . ArgumentList . Add ( Convert . ToBase64String ( Encoding . Unicode . GetBytes ( initCommand ) ) ) ;
95+ }
96+
97+ return psi ;
98+ }
9299}
0 commit comments