@@ -13,6 +13,7 @@ public class StartAIShellCommand : PSCmdlet
1313
1414 private string _venvPipPath ;
1515 private string _venvPythonPath ;
16+ private static bool s_iterm2Installed = false ;
1617
1718 protected override void BeginProcessing ( )
1819 {
@@ -166,35 +167,45 @@ protected override void EndProcessing()
166167 }
167168 else if ( OperatingSystem . IsMacOS ( ) )
168169 {
170+ Process proc ;
171+ ProcessStartInfo startInfo ;
172+
169173 // Install the Python package 'iterm2' to the venv.
170- ProcessStartInfo startInfo = new ( _venvPipPath )
174+ if ( ! s_iterm2Installed )
171175 {
172- ArgumentList = { "install" , "-q" , "iterm2" , "--disable-pip-version-check" } ,
173- RedirectStandardError = true ,
174- RedirectStandardOutput = true
175- } ;
176+ startInfo = new ( _venvPipPath )
177+ {
178+ ArgumentList = { "install" , "-q" , "iterm2" , "--disable-pip-version-check" } ,
179+ RedirectStandardError = true ,
180+ RedirectStandardOutput = true
181+ } ;
176182
177- Process proc = Process . Start ( startInfo ) ;
178- proc . WaitForExit ( ) ;
183+ proc = Process . Start ( startInfo ) ;
184+ proc . WaitForExit ( ) ;
179185
180- if ( proc . ExitCode is 1 )
181- {
182- string error = "The Python package 'iterm2' cannot be installed. It's required to split a pane in iTerm2 programmatically." ;
183- string stderr = proc . StandardError . ReadToEnd ( ) ;
184- if ( ! string . IsNullOrEmpty ( stderr ) )
186+ if ( proc . ExitCode is 0 )
185187 {
186- error = $ "{ error } \n Error details:\n { stderr } ";
188+ s_iterm2Installed = true ;
189+ }
190+ else
191+ {
192+ string error = "The Python package 'iterm2' cannot be installed. It's required to split a pane in iTerm2 programmatically." ;
193+ string stderr = proc . StandardError . ReadToEnd ( ) ;
194+ if ( ! string . IsNullOrEmpty ( stderr ) )
195+ {
196+ error = $ "{ error } \n Error details:\n { stderr } ";
197+ }
198+
199+ ThrowTerminatingError ( new (
200+ new NotSupportedException ( error ) ,
201+ "iterm2Missing" ,
202+ ErrorCategory . NotInstalled ,
203+ targetObject : null ) ) ;
187204 }
188205
189- ThrowTerminatingError ( new (
190- new NotSupportedException ( error ) ,
191- "iterm2Missing" ,
192- ErrorCategory . NotInstalled ,
193- targetObject : null ) ) ;
206+ proc . Dispose ( ) ;
194207 }
195208
196- proc . Dispose ( ) ;
197-
198209 // Run the Python script to split the pane and start AIShell.
199210 string pipeName = Channel . Singleton . StartChannelSetup ( ) ;
200211 startInfo = new ( _venvPythonPath ) { ArgumentList = { InitAndCleanup . PythonScript , Path , pipeName } } ;
0 commit comments