|
7 | 7 | import importlib |
8 | 8 | import logging |
9 | 9 | import os |
| 10 | +import pathlib |
10 | 11 | import sys |
11 | 12 |
|
12 | 13 | import click |
13 | 14 | import kaptan |
| 15 | +from click.shell_completion import CompletionItem |
14 | 16 |
|
15 | 17 | from libtmux.common import has_gte_version, which |
16 | 18 | from libtmux.server import Server |
17 | 19 |
|
18 | 20 | from .. import config, exc, log, util |
19 | 21 | from ..workspacebuilder import WorkspaceBuilder |
20 | | -from .utils import ConfigPath, _validate_choices, tmuxp_echo |
| 22 | +from .utils import ConfigPath, _validate_choices, get_config_dir, tmuxp_echo |
21 | 23 |
|
22 | 24 |
|
23 | 25 | def set_layout_hook(session, hook_name): |
@@ -438,9 +440,22 @@ def load_workspace( |
438 | 440 | return _setup_plugins(builder) |
439 | 441 |
|
440 | 442 |
|
| 443 | +def config_shell_complete(ctx, params, incomplete): |
| 444 | + config_dir = pathlib.Path(get_config_dir()) |
| 445 | + choices = [config_dir / c for c in config.in_dir(str(config_dir))] |
| 446 | + choices += ["~" / f.relative_to(pathlib.Path.home()) for f in choices] |
| 447 | + choices = [str(p) for p in choices] |
| 448 | + return [CompletionItem(choice) for choice in choices if incomplete in choice] |
| 449 | + |
| 450 | + |
441 | 451 | @click.command(name="load", short_help="Load tmuxp workspaces.") |
442 | 452 | @click.pass_context |
443 | | -@click.argument("config", type=ConfigPath(exists=True), nargs=-1) |
| 453 | +@click.argument( |
| 454 | + "config", |
| 455 | + type=ConfigPath(exists=True), |
| 456 | + nargs=-1, |
| 457 | + shell_complete=config_shell_complete, |
| 458 | +) |
444 | 459 | @click.option("-S", "socket_path", help="pass-through for tmux -S") |
445 | 460 | @click.option("-L", "socket_name", help="pass-through for tmux -L") |
446 | 461 | @click.option("-f", "tmux_config_file", help="pass-through for tmux -f") |
|
0 commit comments