@@ -307,6 +307,10 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
307
307
elif 'STY' in os .environ and which ('screen' ):
308
308
terminal = 'screen'
309
309
args = ['-t' ,'pwntools-gdb' ,'bash' ,'-c' ]
310
+ elif 'TERM_PROGRAM' in os .environ and os .environ ['TERM_PROGRAM' ] == "iTerm.app" and which ('osascript' ):
311
+ # if we're on a mac, and using iTerm
312
+ terminal = "osascript"
313
+ args = []
310
314
elif 'TERM_PROGRAM' in os .environ and which (os .environ ['TERM_PROGRAM' ]):
311
315
terminal = os .environ ['TERM_PROGRAM' ]
312
316
args = []
@@ -366,7 +370,6 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
366
370
args .extend (['wsl.exe' , '-d' , distro_name , 'bash' , '-c' ])
367
371
else :
368
372
args .extend (['bash.exe' , '-c' ])
369
-
370
373
371
374
if not terminal :
372
375
log .error ('Could not find a terminal binary to use. Set context.terminal to your terminal.' )
@@ -382,6 +385,27 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
382
385
if terminal == 'tmux' :
383
386
args += ['-F' '#{pane_pid}' , '-P' ]
384
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
+ osa_script = osa_script .format (gdb_command = " " .join (command )).lstrip ()
402
+ with tempfile .NamedTemporaryFile (delete = False , mode = 'wt+' ) as tmp :
403
+ tmp .write (osa_script )
404
+ tmp .flush ()
405
+ os .chmod (tmp .name , 0o700 )
406
+ args = [tmp .name ]
407
+
408
+
385
409
argv = [which (terminal )] + args
386
410
387
411
if isinstance (command , six .string_types ):
0 commit comments