Start work on option to control sourcing strategies

This commit is contained in:
Kovid Goyal
2022-04-17 15:30:57 +05:30
parent f9cad2c4ea
commit 0ee5712e00
6 changed files with 48 additions and 14 deletions

View File

@@ -251,6 +251,7 @@ class Child:
env = {k: v for k, v in env.items() if v is not DELETE_ENV_VAR} env = {k: v for k, v in env.items() if v is not DELETE_ENV_VAR}
if self.is_clone_launch: if self.is_clone_launch:
env['KITTY_IS_CLONE_LAUNCH'] = self.is_clone_launch env['KITTY_IS_CLONE_LAUNCH'] = self.is_clone_launch
env['KITTY_CLONE_SOURCE_STRATEGIES'] = ',' + ','.join(opts.clone_source_strategies) + ','
self.is_clone_launch = '1' # free memory self.is_clone_launch = '1' # free memory
else: else:
env.pop('KITTY_IS_CLONE_LAUNCH', None) env.pop('KITTY_IS_CLONE_LAUNCH', None)

View File

@@ -10,7 +10,8 @@ from .cli import parse_args
from .cli_stub import LaunchCLIOptions from .cli_stub import LaunchCLIOptions
from .constants import kitty_exe, shell_path from .constants import kitty_exe, shell_path
from .fast_data_types import ( from .fast_data_types import (
get_boss, get_os_window_title, patch_color_profiles, set_clipboard_string get_boss, get_options, get_os_window_title, patch_color_profiles,
set_clipboard_string
) )
from .options.utils import env as parse_env from .options.utils import env as parse_env
from .tabs import Tab, TabManager from .tabs import Tab, TabManager
@@ -594,13 +595,18 @@ def clone_and_launch(msg: str, window: Window) -> None:
is_clone_launch = serialize_env(c.shell, c.env or {}) is_clone_launch = serialize_env(c.shell, c.env or {})
ssh_kitten_cmdline = window.ssh_kitten_cmdline() ssh_kitten_cmdline = window.ssh_kitten_cmdline()
if ssh_kitten_cmdline: if ssh_kitten_cmdline:
from kittens.ssh.main import set_cwd_in_cmdline, set_env_in_cmdline, patch_cmdline from kittens.ssh.main import (
patch_cmdline, set_cwd_in_cmdline, set_env_in_cmdline
)
cmdline = ssh_kitten_cmdline cmdline = ssh_kitten_cmdline
if c.opts.cwd: if c.opts.cwd:
set_cwd_in_cmdline(c.opts.cwd, cmdline) set_cwd_in_cmdline(c.opts.cwd, cmdline)
c.opts.cwd = None c.opts.cwd = None
if c.env: if c.env:
set_env_in_cmdline({'KITTY_IS_CLONE_LAUNCH': is_clone_launch}, cmdline) set_env_in_cmdline({
'KITTY_IS_CLONE_LAUNCH': is_clone_launch,
'KITTY_CLONE_SOURCE_STRATEGIES': ',' + ','.join(get_options().clone_source_strategies) + ','
}, cmdline)
c.env = None c.env = None
if c.opts.env: if c.opts.env:
for entry in reversed(c.opts.env): for entry in reversed(c.opts.env):

View File

@@ -2783,6 +2783,23 @@ Allowing cloning unconditionally gives programs running in the terminal
the terminal is running as on the computer the terminal is running on. the terminal is running as on the computer the terminal is running on.
''') ''')
opt('clone_source_strategies', 'venv,conda,env_var,path', option_type='clone_source_strategies', long_text='''
Control what shell code is sourced when running :code:`clone-in-kitty`
in the newly cloned window. The supported strategies are:
:code:`venv`
Source the file :file:`$VIRTUAL_ENV/bin/activate` (this is used
by the Python stdlin venv module and allows cloning venvs automatically)
:code:`conda`
Run :code:`conda activate $CONDA_DEFAULT_ENV` this supports the virtual envs created by conda
:code:`env_var`
Source the contents of the environment variable :code:`KITTY_CLONE_SOURCE_CODE`
:code:`path`
Source the file pointed to by the environment variable :code:`KITTY_CLONE_SOURCE_PATH`
This setting must be a comma separated list of the above values.
''')
opt('term', 'xterm-kitty', opt('term', 'xterm-kitty',
long_text=''' long_text='''
The value of the TERM environment variable to set. Changing this can break many The value of the TERM environment variable to set. Changing this can break many

24
kitty/options/parse.py generated
View File

@@ -8,15 +8,16 @@ from kitty.conf.utils import (
from kitty.options.utils import ( from kitty.options.utils import (
action_alias, active_tab_title_template, adjust_baseline, adjust_line_height, allow_hyperlinks, action_alias, active_tab_title_template, adjust_baseline, adjust_line_height, allow_hyperlinks,
allow_remote_control, bell_on_tab, box_drawing_scale, clear_all_mouse_actions, clear_all_shortcuts, allow_remote_control, bell_on_tab, box_drawing_scale, clear_all_mouse_actions, clear_all_shortcuts,
clipboard_control, config_or_absolute_path, copy_on_select, cursor_text_color, clipboard_control, clone_source_strategies, config_or_absolute_path, copy_on_select,
deprecated_hide_window_decorations_aliases, deprecated_macos_show_window_title_in_menubar_alias, cursor_text_color, deprecated_hide_window_decorations_aliases,
deprecated_send_text, disable_ligatures, edge_width, env, font_features, hide_window_decorations, deprecated_macos_show_window_title_in_menubar_alias, deprecated_send_text, disable_ligatures,
macos_option_as_alt, macos_titlebar_color, narrow_symbols, optional_edge_width, parse_map, edge_width, env, font_features, hide_window_decorations, macos_option_as_alt, macos_titlebar_color,
parse_mouse_map, paste_actions, resize_draw_strategy, scrollback_lines, narrow_symbols, optional_edge_width, parse_map, parse_mouse_map, paste_actions,
scrollback_pager_history_size, shell_integration, store_multiple, symbol_map, tab_activity_symbol, resize_draw_strategy, scrollback_lines, scrollback_pager_history_size, shell_integration,
tab_bar_edge, tab_bar_margin_height, tab_bar_min_tabs, tab_fade, tab_font_style, tab_separator, store_multiple, symbol_map, tab_activity_symbol, tab_bar_edge, tab_bar_margin_height,
tab_title_template, titlebar_color, to_cursor_shape, to_font_size, to_layout_names, to_modifiers, tab_bar_min_tabs, tab_fade, tab_font_style, tab_separator, tab_title_template, titlebar_color,
url_prefixes, url_style, visual_window_select_characters, window_border_width, window_size to_cursor_shape, to_font_size, to_layout_names, to_modifiers, url_prefixes, url_style,
visual_window_select_characters, window_border_width, window_size
) )
@@ -56,7 +57,7 @@ class Parser:
raise ValueError(f"The value {val} is not a valid choice for allow_cloning") raise ValueError(f"The value {val} is not a valid choice for allow_cloning")
ans["allow_cloning"] = val ans["allow_cloning"] = val
choices_for_allow_cloning = frozenset(('yes', 'no', 'ask')) choices_for_allow_cloning = frozenset(('yes', 'y', 'true', 'no', 'n', 'false', 'ask'))
def allow_hyperlinks(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: def allow_hyperlinks(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['allow_hyperlinks'] = allow_hyperlinks(val) ans['allow_hyperlinks'] = allow_hyperlinks(val)
@@ -120,6 +121,9 @@ class Parser:
def clipboard_max_size(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: def clipboard_max_size(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['clipboard_max_size'] = positive_float(val) ans['clipboard_max_size'] = positive_float(val)
def clone_source_strategies(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['clone_source_strategies'] = clone_source_strategies(val)
def close_on_child_death(self, val: str, ans: typing.Dict[str, typing.Any]) -> None: def close_on_child_death(self, val: str, ans: typing.Dict[str, typing.Any]) -> None:
ans['close_on_child_death'] = to_bool(val) ans['close_on_child_death'] = to_bool(val)

View File

@@ -13,7 +13,7 @@ from kitty.types import FloatEdges, SingleKey
import kitty.types import kitty.types
if typing.TYPE_CHECKING: if typing.TYPE_CHECKING:
choices_for_allow_cloning = typing.Literal['yes', 'no', 'ask'] choices_for_allow_cloning = typing.Literal['yes', 'y', 'true', 'no', 'n', 'false', 'ask']
choices_for_background_image_layout = typing.Literal['mirror-tiled', 'scaled', 'tiled', 'clamped'] choices_for_background_image_layout = typing.Literal['mirror-tiled', 'scaled', 'tiled', 'clamped']
choices_for_default_pointer_shape = typing.Literal['arrow', 'beam', 'hand'] choices_for_default_pointer_shape = typing.Literal['arrow', 'beam', 'hand']
choices_for_linux_display_server = typing.Literal['auto', 'wayland', 'x11'] choices_for_linux_display_server = typing.Literal['auto', 'wayland', 'x11']
@@ -73,6 +73,7 @@ option_names = ( # {{{
'click_interval', 'click_interval',
'clipboard_control', 'clipboard_control',
'clipboard_max_size', 'clipboard_max_size',
'clone_source_strategies',
'close_on_child_death', 'close_on_child_death',
'color0', 'color0',
'color1', 'color1',
@@ -484,6 +485,7 @@ class Options:
click_interval: float = -1.0 click_interval: float = -1.0
clipboard_control: typing.Tuple[str, ...] = ('write-clipboard', 'write-primary', 'read-clipboard-ask', 'read-primary-ask') clipboard_control: typing.Tuple[str, ...] = ('write-clipboard', 'write-primary', 'read-clipboard-ask', 'read-primary-ask')
clipboard_max_size: float = 64.0 clipboard_max_size: float = 64.0
clone_source_strategies: typing.FrozenSet[str] = frozenset({'venv', 'env_var', 'conda', 'path'})
close_on_child_death: bool = False close_on_child_death: bool = False
command_on_bell: typing.List[str] = ['none'] command_on_bell: typing.List[str] = ['none']
confirm_os_window_close: int = -1 confirm_os_window_close: int = -1

View File

@@ -746,6 +746,10 @@ def tab_bar_margin_height(x: str) -> TabBarMarginHeight:
return TabBarMarginHeight(next(ans), next(ans)) return TabBarMarginHeight(next(ans), next(ans))
def clone_source_strategies(x: str) -> FrozenSet[str]:
return frozenset({'venv', 'conda', 'path', 'env_var'} & set(x.lower().split(',')))
def clear_all_mouse_actions(val: str, dict_with_parse_results: Optional[Dict[str, Any]] = None) -> bool: def clear_all_mouse_actions(val: str, dict_with_parse_results: Optional[Dict[str, Any]] = None) -> bool:
ans = to_bool(val) ans = to_bool(val)
if ans and dict_with_parse_results is not None: if ans and dict_with_parse_results is not None: