@@ -385,27 +385,6 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
385
385
if terminal == 'tmux' :
386
386
args += ['-F' '#{pane_pid}' , '-P' ]
387
387
388
- # if we're on a Mac and use iTerm
389
- # we use `osascript` to split the current window
390
- if terminal == 'osascript' :
391
- osa_script = """
392
- tell application "iTerm"
393
- tell current session of current window
394
- set newSession to (split horizontally with default profile)
395
- end tell
396
- tell newSession
397
- write text "{gdb_command}"
398
- end tell
399
- end tell
400
- """
401
- gdb_command = " " .join (command ).replace ('"' , '\\ "' ).replace ("'" , "\\ '" )
402
- osa_script = osa_script .format (gdb_command = gdb_command ).lstrip ()
403
- with tempfile .NamedTemporaryFile (delete = False , mode = 'wt+' ) as tmp :
404
- tmp .write (osa_script )
405
- tmp .flush ()
406
- os .chmod (tmp .name , 0o700 )
407
- args = [tmp .name ]
408
-
409
388
410
389
argv = [which (terminal )] + args
411
390
@@ -435,6 +414,27 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
435
414
argv += [tmp .name ]
436
415
437
416
417
+ # if we're on a Mac and use iTerm, we use `osascript` to split the current window
418
+ # `command` was sanitized on the previous step. It is now either a string, or was written to a tmp file
419
+ # we run the command, which is now `argv[-1]`
420
+ if terminal == 'osascript' :
421
+ osa_script = f"""
422
+ tell application "iTerm"
423
+ tell current session of current window
424
+ set newSession to (split horizontally with default profile)
425
+ end tell
426
+ tell newSession
427
+ write text "{ argv [- 1 ]} "
428
+ end tell
429
+ end tell
430
+ """
431
+ with tempfile .NamedTemporaryFile (delete = False , mode = 'wt+' ) as tmp :
432
+ tmp .write (osa_script .lstrip ())
433
+ tmp .flush ()
434
+ os .chmod (tmp .name , 0o700 )
435
+ argv = [which (terminal ), tmp .name ]
436
+
437
+
438
438
log .debug ("Launching a new terminal: %r" % argv )
439
439
440
440
stdin = stdout = stderr = open (os .devnull , 'r+b' )
0 commit comments