From 5ad55dd165fbe455253833dfdf72b56b8aabe57f Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Tue, 9 Aug 2022 15:56:39 +0530 Subject: [PATCH] Allow using file completion for any type of command line arg --- kitty/cli.py | 12 +++--------- kitty/complete.py | 12 ++---------- kitty/launch.py | 3 ++- 3 files changed, 7 insertions(+), 20 deletions(-) diff --git a/kitty/cli.py b/kitty/cli.py index 119b92680..fcd6a8976 100644 --- a/kitty/cli.py +++ b/kitty/cli.py @@ -451,8 +451,6 @@ def as_type_stub(seq: OptionSpecSeq, disabled: OptionSpecSeq, class_name: str, e t = 'typing.Optional[str]' elif otype == 'list': t = 'typing.Sequence[str]' - elif otype == 'path': - t = 'str' elif otype in ('choice', 'choices'): if opt['choices']: t = 'typing.Literal[{}]'.format(','.join(f'{x!r}' for x in opt['choices'])) @@ -535,8 +533,6 @@ class Options: raise SystemExit('{} is not a valid value for the {} option. Valid values are: {}'.format( val, emph(alias), ', '.join(choices))) self.values_map[name] = val - elif typ == 'path': - self.values_map[name] = val elif typ in nmap: f = nmap[typ] try: @@ -616,6 +612,7 @@ are running a program that does not set titles. --config -c type=list +completion=type:file ext:conf group:"Config files" {config_help} @@ -627,7 +624,6 @@ Syntax: :italic:`name=value`. For example: :option:`{appname} -o` font_size=20 --directory --working-directory -d default=. -type=path completion=type:directory Change to the specified directory when launching. @@ -639,8 +635,7 @@ Detach from the controlling terminal, if any. --session -type=path -completion=ext:session relative:conf group:"Session files" +completion=type:file ext:session relative:conf group:"Session files" Path to a file containing the startup :italic:`session` (tabs, windows, layout, programs). Use - to read from STDIN. See the :file:`README` file for details and an example. Environment variables are expanded, relative paths are resolved relative @@ -748,8 +743,7 @@ present in the main font. --watcher -type=path -completion=ext:py relative:conf group:"Watcher files" +completion=type:file ext:py relative:conf group:"Watcher files" This option is deprecated in favor of the :opt:`watcher` option in :file:`{conf_name}.conf` and should not be used. diff --git a/kitty/complete.py b/kitty/complete.py index 15eb09b5f..68163d339 100644 --- a/kitty/complete.py +++ b/kitty/complete.py @@ -386,14 +386,6 @@ def complete_kitty_cli_arg(ans: Completions, opt: Optional[OptionDict], prefix: from kitty.config import option_names_for_completion k = 'Config directives' ans.add_match_group(k, {k+'=': '' for k in option_names_for_completion() if k.startswith(prefix)}, trailing_space=False) - elif dest == 'config': - - def is_conf_file(x: str) -> bool: - if os.path.isdir(x): - return True - return x.lower().endswith('.conf') - - complete_files_and_dirs(ans, prefix, files_group_name='Config files', predicate=is_conf_file) elif dest == 'listen_on': if ':' not in prefix: k = 'Address type' @@ -644,7 +636,7 @@ def complete_file_path(ans: Completions, spec: Dict[str, str], prefix: str, only def complete_path(ans: Completions, opt: OptionDict, prefix: str) -> None: spec = opt['completion'] - t = spec.get('type', 'file') + t = spec['type'] if t == 'file': complete_file_path(ans, spec, prefix) elif t == 'directory': @@ -654,7 +646,7 @@ def complete_path(ans: Completions, opt: OptionDict, prefix: str) -> None: def complete_basic_option_args(ans: Completions, opt: OptionDict, prefix: str) -> None: if opt['choices']: ans.add_match_group(f'Choices for {opt["dest"]}', tuple(k for k in opt['choices'] if k.startswith(prefix))) - elif opt['type'] == 'path': + elif opt['completion'].get('type') in ('file', 'directory'): complete_path(ans, opt, prefix) diff --git a/kitty/launch.py b/kitty/launch.py index 9c767182d..13fa3f4c8 100644 --- a/kitty/launch.py +++ b/kitty/launch.py @@ -201,7 +201,7 @@ use the title of the current OS window, if any. --logo type=path -completion=ext:png group:"PNG images" relative:conf +completion=type:file ext:png group:"PNG images" relative:conf Path to a PNG image to use as the logo for the newly created window. See :opt:`window_logo_path`. Relative paths are resolved from the kitty configuration directory. @@ -228,6 +228,7 @@ from, or specify them individually, for example: :code:`--color background=white --watcher -w type=list +completion=type:file ext:py relative:conf group:"Python scripts" Path to a Python file. Appropriately named functions in this file will be called for various events, such as when the window is resized, focused or closed. See the section on watchers in the launch command documentation: :ref:`watchers`.