@@ -258,6 +258,8 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
258
258
- If ``$TERM_PROGRAM`` is set, that is used.
259
259
- If X11 is detected (by the presence of the ``$DISPLAY`` environment
260
260
variable), ``x-terminal-emulator`` is used.
261
+ - If KDE Konsole is detected (by the presence of the ``$KONSOLE_VERSION``
262
+ environment variable), a terminal will be split.
261
263
- If WSL (Windows Subsystem for Linux) is detected (by the presence of
262
264
a ``wsl.exe`` binary in the ``$PATH`` and ``/proc/sys/kernel/osrelease``
263
265
containing ``Microsoft``), a new ``cmd.exe`` window will be opened.
@@ -297,6 +299,23 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
297
299
elif 'DISPLAY' in os .environ and which ('x-terminal-emulator' ):
298
300
terminal = 'x-terminal-emulator'
299
301
args = ['-e' ]
302
+ elif 'KONSOLE_VERSION' in os .environ and which ('qdbus' ):
303
+ konsole_window = os .environ ['KONSOLE_DBUS_WINDOW' ].split ('/' )[- 1 ]
304
+ konsole_dbus_service = os .environ ['KONSOLE_DBUS_SERVICE' ]
305
+ qdbus = which ('qdbus' )
306
+ # SPLIT
307
+ subprocess .run ((qdbus , konsole_dbus_service , '/konsole/MainWindow_{}' .format (konsole_window ),
308
+ 'org.kde.KMainWindow.activateAction' , 'split-view-left-right' ), stdout = subprocess .DEVNULL )
309
+
310
+ with subprocess .Popen ((qdbus , konsole_dbus_service , os .environ ['KONSOLE_DBUS_WINDOW' ],
311
+ 'org.kde.konsole.Window.sessionList' ), stdout = subprocess .PIPE ) as proc :
312
+ session_list = map (int , proc .communicate ()[0 ].decode ().split ())
313
+ last_konsole_session = max (session_list )
314
+
315
+ terminal = 'qdbus'
316
+ args = [konsole_dbus_service , '/Sessions/{}' .format (last_konsole_session ),
317
+ 'org.kde.konsole.Session.runCommand' ]
318
+
300
319
else :
301
320
is_wsl = False
302
321
if os .path .exists ('/proc/sys/kernel/osrelease' ):
@@ -359,13 +378,20 @@ def run_in_new_terminal(command, terminal=None, args=None, kill_at_exit=True, pr
359
378
if terminal == 'tmux' :
360
379
out , _ = p .communicate ()
361
380
pid = int (out )
381
+ elif terminal == 'qdbus' :
382
+ with subprocess .Popen ((qdbus , konsole_dbus_service , '/Sessions/{}' .format (last_konsole_session ),
383
+ 'org.kde.konsole.Session.processId' ), stdout = subprocess .PIPE ) as proc :
384
+ pid = int (proc .communicate ()[0 ].decode ())
362
385
else :
363
386
pid = p .pid
364
387
365
388
if kill_at_exit :
366
389
def kill ():
367
390
try :
368
- os .kill (pid , signal .SIGTERM )
391
+ if terminal == 'qdbus' :
392
+ os .kill (pid , signal .SIGHUP )
393
+ else :
394
+ os .kill (pid , signal .SIGTERM )
369
395
except OSError :
370
396
pass
371
397
0 commit comments