From 9b632a995111b9afea04a524f5cb6e70680176bd Mon Sep 17 00:00:00 2001 From: Paul Morelle Date: Mon, 25 Jan 2016 23:37:05 +0100 Subject: [PATCH 1/4] Allow multiple configuration files on command line Fixes tony/tmuxp#133 as far as I'm concerned --- tmuxp/cli.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tmuxp/cli.py b/tmuxp/cli.py index b850b0e09f..8fa2e78793 100644 --- a/tmuxp/cli.py +++ b/tmuxp/cli.py @@ -399,7 +399,11 @@ def command_load(args): """Load a session from a tmuxp session file.""" if isinstance(args.config, list): - args.config = ' '.join(args.config) + for config in args.config: + new_args = argparse.Namespace(**args.__dict__) + new_args.config = config + command_load(new_args) + return if '.' == args.config: if config.in_cwd(): From 29ca74846ddbc74ecdac373237736930ec3466cd Mon Sep 17 00:00:00 2001 From: Paul Morelle Date: Tue, 26 Jan 2016 21:13:12 -0500 Subject: [PATCH 2/4] Load first configurations to the background Only the last one will be attached if -d flag is not specified --- tmuxp/cli.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tmuxp/cli.py b/tmuxp/cli.py index 8fa2e78793..268eec511d 100644 --- a/tmuxp/cli.py +++ b/tmuxp/cli.py @@ -399,10 +399,17 @@ def command_load(args): """Load a session from a tmuxp session file.""" if isinstance(args.config, list): - for config in args.config: + # Load each configuration but the last to the background + for config in args.config[:-1]: new_args = argparse.Namespace(**args.__dict__) + new_args.detached = True new_args.config = config command_load(new_args) + + # The last one will be detached if specified on the command line + new_args = argparse.Namespace(**args.__dict__) + new_args.config = args.config[-1] + command_load(new_args) return if '.' == args.config: From b103dcb460655dd0c89009ba446d368ff3ea4076 Mon Sep 17 00:00:00 2001 From: Paul Morelle Date: Wed, 27 Jan 2016 10:25:39 -0500 Subject: [PATCH 3/4] Documentation for multi-config loading behaviour --- doc/cli.rst | 8 ++++++++ tmuxp/cli.py | 7 ++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/doc/cli.rst b/doc/cli.rst index 2f3d340e33..11b4dcef0e 100644 --- a/doc/cli.rst +++ b/doc/cli.rst @@ -73,6 +73,14 @@ Load session $ tmuxp load . + Multiple sessions can be loaded at once. The first ones will be created + without being attached. The last one will be attached if there is no + ``-d`` flag on the command line. + + .. code-block:: bash + + $ tmuxp load ... + .. _cli_import: Import diff --git a/tmuxp/cli.py b/tmuxp/cli.py index 268eec511d..1c43ba43a9 100644 --- a/tmuxp/cli.py +++ b/tmuxp/cli.py @@ -829,8 +829,9 @@ def get_parser(): load = subparsers.add_parser( 'load', parents=[server_parser, client_parser], - help='Load a configuration from file. Attach the session. If session ' - 'already exists, offer to attach instead.' + help='Load configurations from one or more files. ' + 'Attach to the session described by the last file. ' + 'If it already exists, offer to attach instead.' ) load.add_argument( @@ -847,7 +848,7 @@ def get_parser(): '-d', dest='detached', default=None, - help='Load a session without attaching to it.', + help='Load the last session without attaching to it.', action='store_true' ) From 92be336833bae4652067c301084471385dd1d103 Mon Sep 17 00:00:00 2001 From: Paul Morelle Date: Wed, 27 Jan 2016 16:53:40 -0500 Subject: [PATCH 4/4] Rename for-loop variable name to avoid conflict Local `config` was hidding global import `config`, used later in the function. --- tmuxp/cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tmuxp/cli.py b/tmuxp/cli.py index 1c43ba43a9..6ce6d3e7de 100644 --- a/tmuxp/cli.py +++ b/tmuxp/cli.py @@ -400,10 +400,10 @@ def command_load(args): if isinstance(args.config, list): # Load each configuration but the last to the background - for config in args.config[:-1]: + for cfg in args.config[:-1]: new_args = argparse.Namespace(**args.__dict__) new_args.detached = True - new_args.config = config + new_args.config = cfg command_load(new_args) # The last one will be detached if specified on the command line