Skip to content

Commit 86e9cde

Browse files
committed
Add options for shell options
Make it possible to pass window_name and shell command to server.new_session Make it possible to pass shell command to window.split_window Signed-off-by: Jo De Boeck <[email protected]>
1 parent 04b1379 commit 86e9cde

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

libtmux/server.py

+20
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ def new_session(self,
409409
kill_session=False,
410410
attach=False,
411411
start_directory=None,
412+
window_name=None,
413+
shell=None,
412414
*args,
413415
**kwargs):
414416
"""Return :class:`Session` from ``$ tmux new-session``.
@@ -441,6 +443,18 @@ def new_session(self,
441443
new session is created.
442444
:type start_directory: str
443445
446+
:param window_name: window name::
447+
448+
$ tmux new-session -n <window_name>
449+
450+
:type session_name: str
451+
:param shell: execute a command on starting the session. The
452+
window will close when the command exits.
453+
NOTE: When this command exits the window will close. This feature
454+
is useful for long-running processes where the closing of the
455+
window upon completion is desired.
456+
:type window_command: str
457+
444458
:raises: :exc:`exc.BadSessionName`
445459
:rtype: :class:`Session`
446460
@@ -477,11 +491,17 @@ def new_session(self,
477491
if start_directory:
478492
tmux_args += ('-c', start_directory)
479493

494+
if window_name:
495+
tmux_args += ('-n', window_name)
496+
480497
# tmux 2.6 gives unattached sessions a tiny default area
481498
# no need send in -x/-y if they're in a client already, though
482499
if has_gte_version('2.6') and 'TMUX' not in os.environ:
483500
tmux_args += ('-x', 800, '-y', 600)
484501

502+
if shell:
503+
tmux_args += (shell, )
504+
485505
proc = self.cmd(
486506
'new-session',
487507
*tmux_args

libtmux/window.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,8 @@ def split_window(
351351
target=None,
352352
start_directory=None,
353353
attach=True,
354-
vertical=True
354+
vertical=True,
355+
shell=None
355356
):
356357
"""Split window and return the created :class:`Pane`.
357358
@@ -379,6 +380,12 @@ def split_window(
379380
:type target: bool
380381
:param vertical: split vertically
381382
:type vertical: bool
383+
:param shell: execute a command on splitting the window. The
384+
pane will close when the command exits.
385+
NOTE: When this command exits the pane will close. This feature
386+
is useful for long-running processes where the closing of the
387+
window upon completion is desired.
388+
:type shell: str
382389
383390
:rtype: :class:`Pane`
384391
@@ -414,6 +421,9 @@ def split_window(
414421
if not attach:
415422
tmux_args += ('-d',)
416423

424+
if shell:
425+
tmux_args += (shell, )
426+
417427
pane = self.cmd(
418428
'split-window',
419429
*tmux_args

0 commit comments

Comments
 (0)