diff --git a/kittens/ssh/copy.py b/kittens/ssh/copy.py new file mode 100644 index 000000000..19dda070b --- /dev/null +++ b/kittens/ssh/copy.py @@ -0,0 +1,6 @@ +#!/usr/bin/env python +# License: GPLv3 Copyright: 2022, Kovid Goyal + + +class CopyInstruction: + pass diff --git a/kittens/ssh/options/definition.py b/kittens/ssh/options/definition.py index 7ddcb285a..2c3b29c1e 100644 --- a/kittens/ssh/options/definition.py +++ b/kittens/ssh/options/definition.py @@ -26,18 +26,9 @@ against is the hostname used by the remote computer, not the name you pass to SSH to connect to it. ''') -opt('remote_dir', '.local/share/kitty-ssh-kitten', option_type='relative_dir', long_text=''' -The location on the remote computer where the files needed for this kitten -are installed. The location is relative to the HOME directory. Absolute paths or paths -that resolve to a location outside the HOME are not allowed. +opt('+copy', '', option_type='copy', add_to_default=False, long_text=''' ''') -opt('shell_integration', 'inherit', long_text=''' -Control the shell integration on the remote host. See ref:`shell_integration` -for details on how this setting works. The special value :code:`inherit` means -use the setting from kitty.conf. This setting is useful for overriding -integration on a per-host basis.''') - opt('+env', '', option_type='env', add_to_default=False, long_text=''' Specify environment variables to set on the remote host. Note that environment variables can refer to each other, so if you use:: @@ -51,4 +42,18 @@ will delete the variable from the child process' environment. The definitions are processed alphabetically. The special value :code:`_kitty_copy_env_var_` will cause the value of the variable to be copied from the local machine. ''') + +opt('remote_dir', '.local/share/kitty-ssh-kitten', option_type='relative_dir', long_text=''' +The location on the remote computer where the files needed for this kitten +are installed. The location is relative to the HOME directory. Absolute paths or paths +that resolve to a location outside the HOME are not allowed. +''') + +opt('shell_integration', 'inherit', long_text=''' +Control the shell integration on the remote host. See ref:`shell_integration` +for details on how this setting works. The special value :code:`inherit` means +use the setting from kitty.conf. This setting is useful for overriding +integration on a per-host basis.''') + + egr() # }}} diff --git a/kittens/ssh/options/parse.py b/kittens/ssh/options/parse.py index dbd789b97..69fe7adbb 100644 --- a/kittens/ssh/options/parse.py +++ b/kittens/ssh/options/parse.py @@ -1,12 +1,16 @@ # generated by gen-config.py DO NOT edit import typing -from kittens.ssh.options.utils import env, hostname +from kittens.ssh.options.utils import copy, env, hostname, relative_dir from kitty.conf.utils import merge_dicts class Parser: + def copy(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: + for k, v in copy(val, ans["copy"]): + ans["copy"][k] = v + def env(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: for k, v in env(val, ans["env"]): ans["env"][k] = v @@ -15,7 +19,7 @@ class Parser: hostname(val, ans) def remote_dir(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: - ans['remote_dir'] = str(val) + ans['remote_dir'] = relative_dir(val) def shell_integration(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: ans['shell_integration'] = str(val) @@ -23,6 +27,7 @@ class Parser: def create_result_dict() -> typing.Dict[str, typing.Any]: return { + 'copy': {}, 'env': {}, } diff --git a/kittens/ssh/options/types.py b/kittens/ssh/options/types.py index f5688da0f..03922bafb 100644 --- a/kittens/ssh/options/types.py +++ b/kittens/ssh/options/types.py @@ -1,16 +1,18 @@ # generated by gen-config.py DO NOT edit import typing +import kittens.ssh.copy option_names = ( # {{{ - 'env', 'hostname', 'remote_dir', 'shell_integration') # }}} + 'copy', 'env', 'hostname', 'remote_dir', 'shell_integration') # }}} class Options: hostname: str = '*' remote_dir: str = '.local/share/kitty-ssh-kitten' shell_integration: str = 'inherit' + copy: typing.Dict[str, kittens.ssh.copy.CopyInstruction] = {} env: typing.Dict[str, str] = {} config_paths: typing.Tuple[str, ...] = () config_overrides: typing.Tuple[str, ...] = () @@ -62,4 +64,5 @@ class Options: defaults = Options() +defaults.copy = {} defaults.env = {} diff --git a/kittens/ssh/options/utils.py b/kittens/ssh/options/utils.py index 9eeca2185..fa3eed8af 100644 --- a/kittens/ssh/options/utils.py +++ b/kittens/ssh/options/utils.py @@ -4,6 +4,8 @@ from typing import Any, Dict, Optional, Iterable, Tuple import posixpath +from ..copy import CopyInstruction + DELETE_ENV_VAR = '_delete_this_env_var_' @@ -30,6 +32,10 @@ def env(val: str, current_val: Dict[str, str]) -> Iterable[Tuple[str, str]]: yield val, DELETE_ENV_VAR +def copy(val: str, current_val: Dict[str, str]) -> Iterable[Tuple[str, CopyInstruction]]: + pass + + def init_results_dict(ans: Dict[str, Any]) -> Dict[str, Any]: ans['hostname'] = '*' ans['per_host_dicts'] = {} diff --git a/kitty/conf/generate.py b/kitty/conf/generate.py index 3b47d4712..b340a31fe 100644 --- a/kitty/conf/generate.py +++ b/kitty/conf/generate.py @@ -38,6 +38,7 @@ def generate_class(defn: Definition, loc: str) -> Tuple[str, str]: choices = {} imports: Set[Tuple[str, str]] = set() tc_imports: Set[Tuple[str, str]] = set() + ki_imports: 're.Pattern[str]' = re.compile(r'\b((?:kittens|kitty).+?)[,\]]') def option_type_as_str(x: Any) -> str: needs_import = False @@ -61,6 +62,11 @@ def generate_class(defn: Definition, loc: str) -> Tuple[str, str]: if isinstance(option, MultiOption): typ = typ[typ.index('[') + 1:-1] typ = typ.replace('Tuple', 'Dict', 1) + kq = ki_imports.search(typ) + if kq is not None: + kqi = kq.group(1) + kqim, kqii = kqi.rsplit('.', 1) + imports.add((kqim, '')) return func, typ is_mutiple_vars = {} @@ -343,14 +349,17 @@ def generate_class(defn: Definition, loc: str) -> Tuple[str, str]: for mod, name in imports: mmap.setdefault(mod, []).append(name) for mod in sorted(mmap): - names = sorted(mmap[mod]) - lines = textwrap.wrap(', '.join(names), 100) - if len(lines) == 1: - s = lines[0] + names = list(filter(None, sorted(mmap[mod]))) + if names: + lines = textwrap.wrap(', '.join(names), 100) + if len(lines) == 1: + s = lines[0] + else: + s = '\n '.join(lines) + s = f'(\n {s}\n)' + a(f'from {mod} import {s}') else: - s = '\n '.join(lines) - s = f'(\n {s}\n)' - a(f'from {mod} import {s}') + s = '' if add_module_imports and mod not in seen_mods and mod != s: a(f'import {mod}') seen_mods.add(mod) diff --git a/kitty/options/types.py b/kitty/options/types.py index 19c45dfb4..707ce8329 100644 --- a/kitty/options/types.py +++ b/kitty/options/types.py @@ -6,6 +6,7 @@ from kitty.constants import is_macos import kitty.constants from kitty.fast_data_types import Color import kitty.fast_data_types +import kitty.fonts from kitty.options.utils import AliasMap, KeyDefinition, KeyMap, MouseMap, MouseMapping, SequenceMap, TabBarMarginHeight import kitty.options.utils from kitty.types import FloatEdges, SingleKey