Skip to content

Commit 64c857e

Browse files
committed
feat(cli): Basic project-based shell completion
1 parent 52d9c0d commit 64c857e

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

tmuxp/cli/load.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,19 @@
77
import importlib
88
import logging
99
import os
10+
import pathlib
1011
import sys
1112

1213
import click
1314
import kaptan
15+
from click.shell_completion import CompletionItem
1416

1517
from libtmux.common import has_gte_version, which
1618
from libtmux.server import Server
1719

1820
from .. import config, exc, log, util
1921
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
2123

2224

2325
def set_layout_hook(session, hook_name):
@@ -438,9 +440,22 @@ def load_workspace(
438440
return _setup_plugins(builder)
439441

440442

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+
441451
@click.command(name="load", short_help="Load tmuxp workspaces.")
442452
@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+
)
444459
@click.option("-S", "socket_path", help="pass-through for tmux -S")
445460
@click.option("-L", "socket_name", help="pass-through for tmux -L")
446461
@click.option("-f", "tmux_config_file", help="pass-through for tmux -f")

0 commit comments

Comments
 (0)