Skip to content

Shell completion #770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion tmuxp/cli/freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@
from .utils import _validate_choices, get_abs_path, get_config_dir


def session_completion(ctx, params, incomplete):
t = Server()
choices = [session.name for session in t.list_sessions()]
return sorted([str(c) for c in choices if str(c).startswith(incomplete)])


@click.command(name="freeze")
@click.argument("session_name", nargs=1, required=False)
@click.argument(
"session_name", nargs=1, required=False, shell_complete=session_completion
)
@click.option("-S", "socket_path", help="pass-through for tmux -S")
@click.option("-L", "socket_name", help="pass-through for tmux -L")
@click.option(
Expand Down
35 changes: 33 additions & 2 deletions tmuxp/cli/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
import importlib
import logging
import os
import pathlib
import sys
from typing import List

import click
import kaptan
Expand All @@ -17,7 +19,7 @@

from .. import config, exc, log, util
from ..workspacebuilder import WorkspaceBuilder
from .utils import ConfigPath, _validate_choices, tmuxp_echo
from .utils import ConfigPath, _validate_choices, get_config_dir, tmuxp_echo


def set_layout_hook(session, hook_name):
Expand Down Expand Up @@ -438,9 +440,38 @@ def load_workspace(
return _setup_plugins(builder)


def config_file_completion(ctx, params, incomplete):
config_dir = pathlib.Path(get_config_dir())
choices: List[pathlib.Path] = []

# CWD Paths
choices += sorted(
[
pathlib.Path(os.path.relpath(p, pathlib.Path.cwd()))
for p in [pathlib.Path.cwd(), *pathlib.Path.cwd().parents]
if config.in_dir(str(p)) or len(list(p.glob(".tmuxp.*")))
]
)
# CWD look one directory up
choices += [
pathlib.Path(f"./{os.path.relpath(p, pathlib.Path.cwd())}")
for p in pathlib.Path.cwd().glob("*/.tmuxp.*")
]

# Project configs
choices += sorted([(config_dir / c).stem for c in config.in_dir(str(config_dir))])

return sorted([str(c) for c in choices if str(c).startswith(incomplete)])


@click.command(name="load", short_help="Load tmuxp workspaces.")
@click.pass_context
@click.argument("config", type=ConfigPath(exists=True), nargs=-1)
@click.argument(
"config",
type=ConfigPath(exists=True),
nargs=-1,
shell_complete=config_file_completion,
)
@click.option("-S", "socket_path", help="pass-through for tmux -S")
@click.option("-L", "socket_name", help="pass-through for tmux -L")
@click.option("-f", "tmux_config_file", help="pass-through for tmux -f")
Expand Down