Skip to content

Commit d210873

Browse files
authored
Merge branch 'master' into confirm-convert
2 parents 3f4f3ae + 7db5972 commit d210873

File tree

7 files changed

+58
-6
lines changed

7 files changed

+58
-6
lines changed

CHANGES

+5-2
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ Changelog
44

55
Here you can find the recent changes to tmuxp
66

7-
current
8-
-------
7+
tmuxp 1.5-current
8+
-----------------
99
- :issue:`589` added option for the the confirm command to auto-confirm the prompt.
10+
- :issue:`626` Add new session name option to cli. Thank you @joseph-flinn!
11+
- :issue:`626` Add test for new session name option
12+
- :issue:`626` Update docs for new session name option
1013
- :issue:`623` Move docs from RTD to self-serve site
1114
- :issue:`623` Modernize Makefiles
1215
- :issue:`623` New development docs

README.rst

+6
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ Load multiple at once (in bg, offer to attach last):
5757
5858
$ tmuxp load mysession ./another/project/
5959
60+
Name a session:
61+
62+
.. code-block:: bash
63+
64+
$ tmxup load -s session_name ./mysession.yaml
65+
6066
`simple`_ and `very elaborate`_ config examples
6167

6268
User-level configurations

docs/cli.rst

+7
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,13 @@ without being attached. The last one will be attached if there is no
8484
8585
$ tmuxp load <filename1> <filename2> ...
8686
87+
A session name can be provided at the terminal. If multiple sessions
88+
are created, the last session is named from the terminal.
89+
90+
.. code-block:: bash
91+
92+
$ tmxup load -s <new_session_name> <filename1> ...
93+
8794
.. _cli_import:
8895

8996
Import

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ skip-string-normalization = true
33

44
[tool.poetry]
55
name = "tmuxp"
6-
version = "1.5.5"
6+
version = "1.5.7"
77
description = "tmux session manager"
88
license = "MIT"
99
authors = ["Tony Narlock <[email protected]>"]

tests/test_cli.py

+19
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,25 @@ def test_load_workspace(server, monkeypatch):
282282
assert session.name == 'sampleconfig'
283283

284284

285+
def test_load_workspace_named_session(server, monkeypatch):
286+
# this is an implementation test. Since this testsuite may be ran within
287+
# a tmux session by the developer himself, delete the TMUX variable
288+
# temporarily.
289+
monkeypatch.delenv('TMUX', raising=False)
290+
session_file = curjoin("workspacebuilder/two_pane.yaml")
291+
292+
# open it detached
293+
session = load_workspace(
294+
session_file,
295+
socket_name=server.socket_name,
296+
new_session_name='tmuxp-new',
297+
detached=True,
298+
)
299+
300+
assert isinstance(session, libtmux.Session)
301+
assert session.name == 'tmuxp-new'
302+
303+
285304
@pytest.mark.skipif(
286305
has_lt_version('2.1'), reason='exact session name matches only tmux >= 2.1'
287306
)

tmuxp/__about__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__title__ = 'tmuxp'
22
__package_name__ = 'tmuxp'
3-
__version__ = '1.5.5'
3+
__version__ = '1.5.7'
44
__description__ = 'tmux session manager'
55
__email__ = '[email protected]'
66
__author__ = 'Tony Narlock'

tmuxp/cli.py

+19-2
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ def load_workspace(
399399
config_file,
400400
socket_name=None,
401401
socket_path=None,
402+
new_session_name=None,
402403
colors=None,
403404
detached=False,
404405
answer_yes=False,
@@ -414,6 +415,8 @@ def load_workspace(
414415
``tmux -L <socket-name>``
415416
socket_path: str, optional
416417
``tmux -S <socket-path>``
418+
new_session_name: str, options
419+
``tmux new -s <new_session_name>``
417420
colors : str, optional
418421
'-2'
419422
Force tmux to support 256 colors
@@ -498,6 +501,9 @@ def load_workspace(
498501
sconfig = sconfig.import_config(config_file).get()
499502
# shapes configurations relative to config / profile file location
500503
sconfig = config.expand(sconfig, os.path.dirname(config_file))
504+
# Overwrite session name
505+
if new_session_name:
506+
sconfig['session_name'] = new_session_name
501507
# propagate config inheritance (e.g. session -> window, window -> pane)
502508
sconfig = config.trickle(sconfig)
503509

@@ -746,6 +752,7 @@ def command_freeze(session_name, socket_name, socket_path):
746752
@click.argument('config', type=ConfigPath(exists=True), nargs=-1)
747753
@click.option('-S', 'socket_path', help='pass-through for tmux -S')
748754
@click.option('-L', 'socket_name', help='pass-through for tmux -L')
755+
@click.option('-s', 'new_session_name', help='start new session with new session name')
749756
@click.option('--yes', '-y', 'answer_yes', help='yes', is_flag=True)
750757
@click.option(
751758
'-d', 'detached', help='Load the session without attaching it', is_flag=True
@@ -763,7 +770,16 @@ def command_freeze(session_name, socket_name, socket_path):
763770
flag_value=88,
764771
help='Like -2, but indicates that the terminal supports 88 colours.',
765772
)
766-
def command_load(ctx, config, socket_name, socket_path, answer_yes, detached, colors):
773+
def command_load(
774+
ctx,
775+
config,
776+
socket_name,
777+
socket_path,
778+
new_session_name,
779+
answer_yes,
780+
detached,
781+
colors,
782+
):
767783
"""Load a tmux workspace from each CONFIG.
768784
769785
CONFIG is a specifier for a configuration file.
@@ -791,6 +807,7 @@ def command_load(ctx, config, socket_name, socket_path, answer_yes, detached, co
791807
tmux_options = {
792808
'socket_name': socket_name,
793809
'socket_path': socket_path,
810+
'new_session_name': new_session_name,
794811
'answer_yes': answer_yes,
795812
'colors': colors,
796813
'detached': detached,
@@ -809,7 +826,7 @@ def command_load(ctx, config, socket_name, socket_path, answer_yes, detached, co
809826
# Load each configuration but the last to the background
810827
for cfg in config[:-1]:
811828
opt = tmux_options.copy()
812-
opt.update({'detached': True})
829+
opt.update({'detached': True, 'new_session_name': None})
813830
load_workspace(cfg, **opt)
814831

815832
# todo: obey the -d in the cli args only if user specifies

0 commit comments

Comments
 (0)