From e239b62b416bfea01d377237feb49e2352b57a7a Mon Sep 17 00:00:00 2001 From: Joseph Flinn Date: Sat, 22 Aug 2020 16:24:04 -0700 Subject: [PATCH 1/5] Adding session name option --- README.rst | 6 ++++++ docs/cli.rst | 7 +++++++ tests/test_cli.py | 19 +++++++++++++++++++ tmuxp/cli.py | 21 +++++++++++++++++++-- 4 files changed, 51 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 55391e4da3f..d209e18e5f4 100644 --- a/README.rst +++ b/README.rst @@ -57,6 +57,12 @@ Load multiple at once (in bg, offer to attach last): $ tmuxp load mysession ./another/project/ +Name a session: + +.. code-block:: bash + + $ tmxup load -n session-name ./mysession.yaml + `simple`_ and `very elaborate`_ config examples User-level configurations diff --git a/docs/cli.rst b/docs/cli.rst index 9fc5ba7b07c..ad9dc63c1cf 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -84,6 +84,13 @@ without being attached. The last one will be attached if there is no $ tmuxp load ... +A session name can be provided at the terminal. If multiple sessions +are created, the last session is named from the terminal. + +.. code-block:: bash + + $ tmxup load -n ... + .. _cli_import: Import diff --git a/tests/test_cli.py b/tests/test_cli.py index 1d5882fe5ce..bfa68e16bd8 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -282,6 +282,25 @@ def test_load_workspace(server, monkeypatch): assert session.name == 'sampleconfig' +def test_load_workspace_named_session(server, monkeypatch): + # this is an implementation test. Since this testsuite may be ran within + # a tmux session by the developer himself, delete the TMUX variable + # temporarily. + monkeypatch.delenv('TMUX', raising=False) + session_file = curjoin("workspacebuilder/two_pane.yaml") + + # open it detached + session = load_workspace( + session_file, + socket_name=server.socket_name, + new_session_name='tmuxp-new', + detached=True + ) + + assert isinstance(session, libtmux.Session) + assert session.name == 'tmuxp-new' + + @pytest.mark.skipif( has_lt_version('2.1'), reason='exact session name matches only tmux >= 2.1' ) diff --git a/tmuxp/cli.py b/tmuxp/cli.py index 35374493568..337f7dce04d 100644 --- a/tmuxp/cli.py +++ b/tmuxp/cli.py @@ -399,6 +399,7 @@ def load_workspace( config_file, socket_name=None, socket_path=None, + new_session_name=None, colors=None, detached=False, answer_yes=False, @@ -414,6 +415,8 @@ def load_workspace( ``tmux -L `` socket_path: str, optional ``tmux -S `` + new_session_name: str, options + ``tmux new -t `` colors : str, optional '-2' Force tmux to support 256 colors @@ -498,6 +501,9 @@ def load_workspace( sconfig = sconfig.import_config(config_file).get() # shapes configurations relative to config / profile file location sconfig = config.expand(sconfig, os.path.dirname(config_file)) + # Overwrite session name + if new_session_name: + sconfig['session_name'] = new_session_name # propagate config inheritance (e.g. session -> window, window -> pane) sconfig = config.trickle(sconfig) @@ -746,6 +752,7 @@ def command_freeze(session_name, socket_name, socket_path): @click.argument('config', type=ConfigPath(exists=True), nargs=-1) @click.option('-S', 'socket_path', help='pass-through for tmux -S') @click.option('-L', 'socket_name', help='pass-through for tmux -L') +@click.option('-n', 'new_session_name', help='name of the new session') @click.option('--yes', '-y', 'answer_yes', help='yes', is_flag=True) @click.option( '-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): flag_value=88, help='Like -2, but indicates that the terminal supports 88 colours.', ) -def command_load(ctx, config, socket_name, socket_path, answer_yes, detached, colors): +def command_load( + ctx, + config, + socket_name, + socket_path, + new_session_name, + answer_yes, + detached, + colors, +): """Load a tmux workspace from each CONFIG. 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 tmux_options = { 'socket_name': socket_name, 'socket_path': socket_path, + 'new_session_name': new_session_name, 'answer_yes': answer_yes, 'colors': colors, 'detached': detached, @@ -809,7 +826,7 @@ def command_load(ctx, config, socket_name, socket_path, answer_yes, detached, co # Load each configuration but the last to the background for cfg in config[:-1]: opt = tmux_options.copy() - opt.update({'detached': True}) + opt.update({'detached': True, 'new_session_name': None}) load_workspace(cfg, **opt) # todo: obey the -d in the cli args only if user specifies From 60acdcec0b00f6bc5dd2c8e4df523399fa0d2e5b Mon Sep 17 00:00:00 2001 From: Joseph Flinn Date: Sat, 22 Aug 2020 17:01:11 -0700 Subject: [PATCH 2/5] ran flake8 to pick up a comma --- tests/test_cli.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_cli.py b/tests/test_cli.py index bfa68e16bd8..f1c921f3aed 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -291,10 +291,10 @@ def test_load_workspace_named_session(server, monkeypatch): # open it detached session = load_workspace( - session_file, - socket_name=server.socket_name, - new_session_name='tmuxp-new', - detached=True + session_file, + socket_name=server.socket_name, + new_session_name='tmuxp-new', + detached=True, ) assert isinstance(session, libtmux.Session) From d2813e832d75400c9df54ff4257cd8c997233075 Mon Sep 17 00:00:00 2001 From: Joseph Flinn Date: Sat, 12 Sep 2020 11:56:35 -0700 Subject: [PATCH 3/5] changed the -n to -s for overloading the session name to reuse a tmuxp config file for multiple sessions --- README.rst | 2 +- docs/cli.rst | 2 +- tmuxp/cli.py | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index d209e18e5f4..9e3139397f7 100644 --- a/README.rst +++ b/README.rst @@ -61,7 +61,7 @@ Name a session: .. code-block:: bash - $ tmxup load -n session-name ./mysession.yaml + $ tmxup load -s session-name ./mysession.yaml `simple`_ and `very elaborate`_ config examples diff --git a/docs/cli.rst b/docs/cli.rst index ad9dc63c1cf..8739cae8506 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -89,7 +89,7 @@ are created, the last session is named from the terminal. .. code-block:: bash - $ tmxup load -n ... + $ tmxup load -s ... .. _cli_import: diff --git a/tmuxp/cli.py b/tmuxp/cli.py index 337f7dce04d..e33e7bec0a8 100644 --- a/tmuxp/cli.py +++ b/tmuxp/cli.py @@ -416,7 +416,7 @@ def load_workspace( socket_path: str, optional ``tmux -S `` new_session_name: str, options - ``tmux new -t `` + ``tmux new -s `` colors : str, optional '-2' Force tmux to support 256 colors @@ -752,7 +752,7 @@ def command_freeze(session_name, socket_name, socket_path): @click.argument('config', type=ConfigPath(exists=True), nargs=-1) @click.option('-S', 'socket_path', help='pass-through for tmux -S') @click.option('-L', 'socket_name', help='pass-through for tmux -L') -@click.option('-n', 'new_session_name', help='name of the new session') +@click.option('-s', 'new_session_name', help='start new session with new session name') @click.option('--yes', '-y', 'answer_yes', help='yes', is_flag=True) @click.option( '-d', 'detached', help='Load the session without attaching it', is_flag=True From c515c797757ae5eff14eee82e740a8d95550e389 Mon Sep 17 00:00:00 2001 From: Joseph Flinn Date: Sat, 12 Sep 2020 12:20:04 -0700 Subject: [PATCH 4/5] Updated docs to reflect underscores instead of dashes to match other documentation --- README.rst | 2 +- docs/cli.rst | 2 +- tmuxp/cli.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/README.rst b/README.rst index 9e3139397f7..48995015ec4 100644 --- a/README.rst +++ b/README.rst @@ -61,7 +61,7 @@ Name a session: .. code-block:: bash - $ tmxup load -s session-name ./mysession.yaml + $ tmxup load -s session_name ./mysession.yaml `simple`_ and `very elaborate`_ config examples diff --git a/docs/cli.rst b/docs/cli.rst index 8739cae8506..ecad270da81 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -89,7 +89,7 @@ are created, the last session is named from the terminal. .. code-block:: bash - $ tmxup load -s ... + $ tmxup load -s ... .. _cli_import: diff --git a/tmuxp/cli.py b/tmuxp/cli.py index e33e7bec0a8..ecbdeae2439 100644 --- a/tmuxp/cli.py +++ b/tmuxp/cli.py @@ -416,7 +416,7 @@ def load_workspace( socket_path: str, optional ``tmux -S `` new_session_name: str, options - ``tmux new -s `` + ``tmux new -s `` colors : str, optional '-2' Force tmux to support 256 colors From 64d5b704b41776dd5b5b101ee4c69691e775dd4b Mon Sep 17 00:00:00 2001 From: Joseph Flinn Date: Sun, 13 Sep 2020 14:40:37 -0700 Subject: [PATCH 5/5] Updating the change log and the versioning documentation --- CHANGES | 10 ++++++++-- pyproject.toml | 2 +- tmuxp/__about__.py | 2 +- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index d91236054ba..6f07233679c 100644 --- a/CHANGES +++ b/CHANGES @@ -4,8 +4,14 @@ Changelog Here you can find the recent changes to tmuxp -current -------- +tmuxp 1.5.7 (2020-09-13) +------------------------ +- :issue:`590` Add new session name option to cli +- :issue:`590` Add test for new session name option +- :issue:`590` Updata docs for new session name option + +tmuxp 1.5.6 (2020-08-16) +------------------------ - :issue:`623` Move docs from RTD to self-serve site - :issue:`623` Modernize Makefiles - :issue:`623` New development docs diff --git a/pyproject.toml b/pyproject.toml index fbddb8d07f9..d3a09729cf7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ skip-string-normalization = true [tool.poetry] name = "tmuxp" -version = "1.5.5" +version = "1.5.7" description = "tmux session manager" license = "MIT" authors = ["Tony Narlock "] diff --git a/tmuxp/__about__.py b/tmuxp/__about__.py index 60528c0e717..962811f3a19 100644 --- a/tmuxp/__about__.py +++ b/tmuxp/__about__.py @@ -1,6 +1,6 @@ __title__ = 'tmuxp' __package_name__ = 'tmuxp' -__version__ = '1.5.5' +__version__ = '1.5.7' __description__ = 'tmux session manager' __email__ = 'tony@git-pull.com' __author__ = 'Tony Narlock'