Skip to content

Session name option #626

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Sep 19, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 7 additions & 0 deletions docs/cli.rst
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ without being attached. The last one will be attached if there is no

$ tmuxp load <filename1> <filename2> ...

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 <new_session_name> <filename1> ...

.. _cli_import:

Import
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 <[email protected]>"]
Expand Down
19 changes: 19 additions & 0 deletions tests/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
)
Expand Down
2 changes: 1 addition & 1 deletion tmuxp/__about__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__title__ = 'tmuxp'
__package_name__ = 'tmuxp'
__version__ = '1.5.5'
__version__ = '1.5.7'
__description__ = 'tmux session manager'
__email__ = '[email protected]'
__author__ = 'Tony Narlock'
Expand Down
21 changes: 19 additions & 2 deletions tmuxp/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -414,6 +415,8 @@ def load_workspace(
``tmux -L <socket-name>``
socket_path: str, optional
``tmux -S <socket-path>``
new_session_name: str, options
``tmux new -s <new_session_name>``
colors : str, optional
'-2'
Force tmux to support 256 colors
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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,
Expand All @@ -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
Expand Down