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/README.rst b/README.rst index 55391e4da3f..48995015ec4 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 -s 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..ecad270da81 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 -s ... + .. _cli_import: Import 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/tests/test_cli.py b/tests/test_cli.py index 1d5882fe5ce..f1c921f3aed 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/__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' diff --git a/tmuxp/cli.py b/tmuxp/cli.py index 35374493568..ecbdeae2439 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 -s `` 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('-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 @@ -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