16
16
from libtmux .common import has_gte_version
17
17
from libtmux .server import Server
18
18
from libtmux .session import Session
19
+ from tmuxp .types import StrPath
19
20
20
21
from .. import config , config_reader , exc , log , util
21
22
from ..workspacebuilder import WorkspaceBuilder
29
30
)
30
31
31
32
if t .TYPE_CHECKING :
32
- from typing_extensions import Literal , TypeAlias
33
+ from typing_extensions import Literal , NotRequired , TypeAlias , TypedDict
33
34
34
35
CLIColorsLiteral : TypeAlias = Literal [56 , 88 ]
35
36
37
+ class OptionOverrides (TypedDict ):
38
+ detached : NotRequired [bool ]
39
+ new_session_name : NotRequired [t .Optional [str ]]
40
+
36
41
37
42
class CLILoadNamespace (argparse .Namespace ):
38
- config_file : str
43
+ config_files : t . List [ str ]
39
44
socket_name : t .Optional [str ]
40
45
socket_path : t .Optional [str ]
41
46
tmux_config_file : t .Optional [str ]
@@ -251,7 +256,7 @@ def _setup_plugins(builder: WorkspaceBuilder) -> Session:
251
256
252
257
253
258
def load_workspace (
254
- config_file : t . Union [ pathlib . Path , str ] ,
259
+ config_file : StrPath ,
255
260
socket_name : t .Optional [str ] = None ,
256
261
socket_path : None = None ,
257
262
tmux_config_file : None = None ,
@@ -266,8 +271,8 @@ def load_workspace(
266
271
267
272
Parameters
268
273
----------
269
- config_file : str
270
- absolute path to config file
274
+ config_file : list of str
275
+ paths or session names to workspace files
271
276
socket_name : str, optional
272
277
``tmux -L <socket-name>``
273
278
socket_path: str, optional
@@ -356,7 +361,7 @@ def load_workspace(
356
361
Accessed April 8th, 2018.
357
362
"""
358
363
# get the canonical path, eliminating any symlinks
359
- if isinstance (config_file , str ):
364
+ if isinstance (config_file , ( str , os . PathLike ) ):
360
365
config_file = pathlib .Path (config_file )
361
366
362
367
tmuxp_echo (
@@ -486,8 +491,9 @@ def config_file_completion(ctx, params, incomplete):
486
491
487
492
488
493
def create_load_subparser (parser : argparse .ArgumentParser ) -> argparse .ArgumentParser :
489
- config_file = parser .add_argument (
490
- "config_file" ,
494
+ config_files = parser .add_argument (
495
+ "config_files" ,
496
+ nargs = "+" ,
491
497
metavar = "config-file" ,
492
498
help = "filepath to session or filename of session if in tmuxp config directory" ,
493
499
)
@@ -568,7 +574,7 @@ def create_load_subparser(parser: argparse.ArgumentParser) -> argparse.ArgumentP
568
574
try :
569
575
import shtab
570
576
571
- config_file .complete = shtab .FILE # type: ignore
577
+ config_files .complete = shtab .FILE # type: ignore
572
578
tmux_config_file .complete = shtab .FILE # type: ignore
573
579
log_file .complete = shtab .FILE # type: ignore
574
580
except ImportError :
@@ -623,27 +629,31 @@ def command_load(
623
629
"append" : args .append ,
624
630
}
625
631
626
- if args .config_file is None :
632
+ if args .config_files is None or len ( args . config_files ) == 0 :
627
633
tmuxp_echo ("Enter at least one config" )
628
634
if parser is not None :
629
635
parser .print_help ()
630
636
sys .exit ()
637
+ return
631
638
632
- config_file = scan_config (args .config_file , config_dir = get_config_dir ())
639
+ last_idx = len (args .config_files ) - 1
640
+ original_options = tmux_options .copy ()
633
641
634
- if isinstance (config_file , str ):
635
- load_workspace (config_file , ** tmux_options )
636
- elif isinstance (config_file , tuple ):
637
- config = list (config_file )
638
- # Load each configuration but the last to the background
639
- for cfg in config [:- 1 ]:
640
- opt = tmux_options .copy ()
641
- opt .update ({"detached" : True , "new_session_name" : None })
642
- load_workspace (cfg , ** opt )
642
+ for idx , config_file in enumerate (args .config_files ):
643
+ config_file = scan_config (config_file , config_dir = get_config_dir ())
643
644
644
- # todo: obey the -d in the cli args only if user specifies
645
- load_workspace (config_file [- 1 ], ** tmux_options )
646
- else :
647
- raise NotImplementedError (
648
- f"config { type (config_file )} with { config_file } not valid"
645
+ detached = tmux_options .pop ("detached" , original_options .get ("detached" , False ))
646
+ new_session_name = tmux_options .pop (
647
+ "new_session_name" , original_options .get ("new_session_name" )
648
+ )
649
+
650
+ if last_idx > 0 and idx < last_idx :
651
+ detached = True
652
+ new_session_name = None
653
+
654
+ load_workspace (
655
+ config_file ,
656
+ detached = detached ,
657
+ new_session_name = new_session_name ,
658
+ ** tmux_options ,
649
659
)
0 commit comments