Skip to content
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

tmuxp load tab completions: Fix tilde #784

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
5 changes: 4 additions & 1 deletion src/tmuxp/cli/load.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import click
import kaptan
from click.shell_completion import CompletionItem

from libtmux.common import has_gte_version
from libtmux.server import Server
Expand Down Expand Up @@ -441,7 +442,9 @@ def load_workspace(
return _setup_plugins(builder)


def config_file_completion(ctx, params, incomplete):
def config_file_completion(
ctx: click.Context, param: click.Parameter, incomplete: str
) -> List[CompletionItem]:
config_dir = pathlib.Path(get_config_dir())
choices: List[pathlib.Path] = []

Expand Down
34 changes: 31 additions & 3 deletions src/tmuxp/cli/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import os
import typing as t

import click
from click.exceptions import FileError
Expand Down Expand Up @@ -84,11 +85,38 @@ def func(value):


class ConfigPath(click.Path):
def __init__(self, config_dir=None, *args, **kwargs):
super().__init__(*args, **kwargs)
def __init__(
self,
config_dir=None,
exists: bool = False,
file_okay: bool = True,
dir_okay: bool = True,
writable: bool = False,
readable: bool = True,
resolve_path: bool = False,
allow_dash: bool = False,
path_type: t.Optional[t.Type] = None,
executable: bool = False,
):
super().__init__(
exists=exists,
file_okay=file_okay,
dir_okay=dir_okay,
writable=writable,
readable=readable,
resolve_path=resolve_path,
allow_dash=allow_dash,
path_type=path_type,
executable=executable,
)
self.config_dir = config_dir

def convert(self, value, param, ctx):
def convert(
self,
value: t.Any,
param: t.Optional[click.Parameter],
ctx: t.Optional[click.Context],
) -> t.Any:
config_dir = self.config_dir
if callable(config_dir):
config_dir = config_dir()
Expand Down