mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-22 16:28:19 +02:00
Start work on copy instructions
This commit is contained in:
6
kittens/ssh/copy.py
Normal file
6
kittens/ssh/copy.py
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
# License: GPLv3 Copyright: 2022, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
|
||||||
|
class CopyInstruction:
|
||||||
|
pass
|
||||||
@@ -26,18 +26,9 @@ against is the hostname used by the remote computer, not the name you pass
|
|||||||
to SSH to connect to it.
|
to SSH to connect to it.
|
||||||
''')
|
''')
|
||||||
|
|
||||||
opt('remote_dir', '.local/share/kitty-ssh-kitten', option_type='relative_dir', long_text='''
|
opt('+copy', '', option_type='copy', add_to_default=False, 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.''')
|
|
||||||
|
|
||||||
opt('+env', '', option_type='env', add_to_default=False, long_text='''
|
opt('+env', '', option_type='env', add_to_default=False, long_text='''
|
||||||
Specify environment variables to set on the remote host. Note that
|
Specify environment variables to set on the remote host. Note that
|
||||||
environment variables can refer to each other, so if you use::
|
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_`
|
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.
|
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() # }}}
|
egr() # }}}
|
||||||
|
|||||||
@@ -1,12 +1,16 @@
|
|||||||
# generated by gen-config.py DO NOT edit
|
# generated by gen-config.py DO NOT edit
|
||||||
|
|
||||||
import typing
|
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
|
from kitty.conf.utils import merge_dicts
|
||||||
|
|
||||||
|
|
||||||
class Parser:
|
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:
|
def env(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
|
||||||
for k, v in env(val, ans["env"]):
|
for k, v in env(val, ans["env"]):
|
||||||
ans["env"][k] = v
|
ans["env"][k] = v
|
||||||
@@ -15,7 +19,7 @@ class Parser:
|
|||||||
hostname(val, ans)
|
hostname(val, ans)
|
||||||
|
|
||||||
def remote_dir(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
|
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:
|
def shell_integration(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
|
||||||
ans['shell_integration'] = str(val)
|
ans['shell_integration'] = str(val)
|
||||||
@@ -23,6 +27,7 @@ class Parser:
|
|||||||
|
|
||||||
def create_result_dict() -> typing.Dict[str, typing.Any]:
|
def create_result_dict() -> typing.Dict[str, typing.Any]:
|
||||||
return {
|
return {
|
||||||
|
'copy': {},
|
||||||
'env': {},
|
'env': {},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,16 +1,18 @@
|
|||||||
# generated by gen-config.py DO NOT edit
|
# generated by gen-config.py DO NOT edit
|
||||||
|
|
||||||
import typing
|
import typing
|
||||||
|
import kittens.ssh.copy
|
||||||
|
|
||||||
|
|
||||||
option_names = ( # {{{
|
option_names = ( # {{{
|
||||||
'env', 'hostname', 'remote_dir', 'shell_integration') # }}}
|
'copy', 'env', 'hostname', 'remote_dir', 'shell_integration') # }}}
|
||||||
|
|
||||||
|
|
||||||
class Options:
|
class Options:
|
||||||
hostname: str = '*'
|
hostname: str = '*'
|
||||||
remote_dir: str = '.local/share/kitty-ssh-kitten'
|
remote_dir: str = '.local/share/kitty-ssh-kitten'
|
||||||
shell_integration: str = 'inherit'
|
shell_integration: str = 'inherit'
|
||||||
|
copy: typing.Dict[str, kittens.ssh.copy.CopyInstruction] = {}
|
||||||
env: typing.Dict[str, str] = {}
|
env: typing.Dict[str, str] = {}
|
||||||
config_paths: typing.Tuple[str, ...] = ()
|
config_paths: typing.Tuple[str, ...] = ()
|
||||||
config_overrides: typing.Tuple[str, ...] = ()
|
config_overrides: typing.Tuple[str, ...] = ()
|
||||||
@@ -62,4 +64,5 @@ class Options:
|
|||||||
|
|
||||||
|
|
||||||
defaults = Options()
|
defaults = Options()
|
||||||
|
defaults.copy = {}
|
||||||
defaults.env = {}
|
defaults.env = {}
|
||||||
|
|||||||
@@ -4,6 +4,8 @@
|
|||||||
from typing import Any, Dict, Optional, Iterable, Tuple
|
from typing import Any, Dict, Optional, Iterable, Tuple
|
||||||
import posixpath
|
import posixpath
|
||||||
|
|
||||||
|
from ..copy import CopyInstruction
|
||||||
|
|
||||||
|
|
||||||
DELETE_ENV_VAR = '_delete_this_env_var_'
|
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
|
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]:
|
def init_results_dict(ans: Dict[str, Any]) -> Dict[str, Any]:
|
||||||
ans['hostname'] = '*'
|
ans['hostname'] = '*'
|
||||||
ans['per_host_dicts'] = {}
|
ans['per_host_dicts'] = {}
|
||||||
|
|||||||
@@ -38,6 +38,7 @@ def generate_class(defn: Definition, loc: str) -> Tuple[str, str]:
|
|||||||
choices = {}
|
choices = {}
|
||||||
imports: Set[Tuple[str, str]] = set()
|
imports: Set[Tuple[str, str]] = set()
|
||||||
tc_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:
|
def option_type_as_str(x: Any) -> str:
|
||||||
needs_import = False
|
needs_import = False
|
||||||
@@ -61,6 +62,11 @@ def generate_class(defn: Definition, loc: str) -> Tuple[str, str]:
|
|||||||
if isinstance(option, MultiOption):
|
if isinstance(option, MultiOption):
|
||||||
typ = typ[typ.index('[') + 1:-1]
|
typ = typ[typ.index('[') + 1:-1]
|
||||||
typ = typ.replace('Tuple', 'Dict', 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
|
return func, typ
|
||||||
|
|
||||||
is_mutiple_vars = {}
|
is_mutiple_vars = {}
|
||||||
@@ -343,14 +349,17 @@ def generate_class(defn: Definition, loc: str) -> Tuple[str, str]:
|
|||||||
for mod, name in imports:
|
for mod, name in imports:
|
||||||
mmap.setdefault(mod, []).append(name)
|
mmap.setdefault(mod, []).append(name)
|
||||||
for mod in sorted(mmap):
|
for mod in sorted(mmap):
|
||||||
names = sorted(mmap[mod])
|
names = list(filter(None, sorted(mmap[mod])))
|
||||||
lines = textwrap.wrap(', '.join(names), 100)
|
if names:
|
||||||
if len(lines) == 1:
|
lines = textwrap.wrap(', '.join(names), 100)
|
||||||
s = lines[0]
|
if len(lines) == 1:
|
||||||
|
s = lines[0]
|
||||||
|
else:
|
||||||
|
s = '\n '.join(lines)
|
||||||
|
s = f'(\n {s}\n)'
|
||||||
|
a(f'from {mod} import {s}')
|
||||||
else:
|
else:
|
||||||
s = '\n '.join(lines)
|
s = ''
|
||||||
s = f'(\n {s}\n)'
|
|
||||||
a(f'from {mod} import {s}')
|
|
||||||
if add_module_imports and mod not in seen_mods and mod != s:
|
if add_module_imports and mod not in seen_mods and mod != s:
|
||||||
a(f'import {mod}')
|
a(f'import {mod}')
|
||||||
seen_mods.add(mod)
|
seen_mods.add(mod)
|
||||||
|
|||||||
1
kitty/options/types.py
generated
1
kitty/options/types.py
generated
@@ -6,6 +6,7 @@ from kitty.constants import is_macos
|
|||||||
import kitty.constants
|
import kitty.constants
|
||||||
from kitty.fast_data_types import Color
|
from kitty.fast_data_types import Color
|
||||||
import kitty.fast_data_types
|
import kitty.fast_data_types
|
||||||
|
import kitty.fonts
|
||||||
from kitty.options.utils import AliasMap, KeyDefinition, KeyMap, MouseMap, MouseMapping, SequenceMap, TabBarMarginHeight
|
from kitty.options.utils import AliasMap, KeyDefinition, KeyMap, MouseMap, MouseMapping, SequenceMap, TabBarMarginHeight
|
||||||
import kitty.options.utils
|
import kitty.options.utils
|
||||||
from kitty.types import FloatEdges, SingleKey
|
from kitty.types import FloatEdges, SingleKey
|
||||||
|
|||||||
Reference in New Issue
Block a user