|
7 | 7 | import importlib
|
8 | 8 | import logging
|
9 | 9 | import os
|
| 10 | +import pathlib |
10 | 11 | import sys
|
| 12 | +from typing import List |
11 | 13 |
|
12 | 14 | import click
|
13 | 15 | import kaptan
|
|
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,40 @@ 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: List[pathlib.Path] = [] |
| 446 | + |
| 447 | + # CWD Paths |
| 448 | + choices += sorted( |
| 449 | + [ |
| 450 | + pathlib.Path(os.path.relpath(p, pathlib.Path.cwd())) |
| 451 | + for p in [pathlib.Path.cwd(), *pathlib.Path.cwd().parents] |
| 452 | + if config.in_dir(str(p)) or len(list(p.glob(".tmuxp.*"))) |
| 453 | + ] |
| 454 | + ) |
| 455 | + # CWD look one directory up |
| 456 | + choices += [ |
| 457 | + pathlib.Path(f"./{os.path.relpath(p, pathlib.Path.cwd())}") |
| 458 | + for p in pathlib.Path.cwd().glob("*/.tmuxp.*") |
| 459 | + ] |
| 460 | + |
| 461 | + # Project configs |
| 462 | + choices += sorted([(config_dir / c).stem for c in config.in_dir(str(config_dir))]) |
| 463 | + # choices += [config_dir / c for c in config.in_dir(str(config_dir))] |
| 464 | + # choices += ["~" / f.relative_to(pathlib.Path.home()) for f in choices] |
| 465 | + |
| 466 | + return sorted([str(c) for c in choices if str(c).startswith(incomplete)]) |
| 467 | + |
| 468 | + |
441 | 469 | @click.command(name="load", short_help="Load tmuxp workspaces.")
|
442 | 470 | @click.pass_context
|
443 |
| -@click.argument("config", type=ConfigPath(exists=True), nargs=-1) |
| 471 | +@click.argument( |
| 472 | + "config", |
| 473 | + type=ConfigPath(exists=True), |
| 474 | + nargs=-1, |
| 475 | + shell_complete=config_shell_complete, |
| 476 | +) |
444 | 477 | @click.option("-S", "socket_path", help="pass-through for tmux -S")
|
445 | 478 | @click.option("-L", "socket_name", help="pass-through for tmux -L")
|
446 | 479 | @click.option("-f", "tmux_config_file", help="pass-through for tmux -f")
|
|
0 commit comments