Ensure the clone launch env var is not set accidentally

This commit is contained in:
Kovid Goyal 2022-04-17 08:29:47 +05:30
parent 74d5f2c259
commit 3af11e92d6
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
3 changed files with 20 additions and 10 deletions

View File

@ -207,9 +207,11 @@ class Child:
stdin: Optional[bytes] = None,
env: Optional[Dict[str, str]] = None,
cwd_from: Optional['CwdRequest'] = None,
allow_remote_control: bool = False
allow_remote_control: bool = False,
is_clone_launch: str = '',
):
self.allow_remote_control = allow_remote_control
self.is_clone_launch = is_clone_launch
self.argv = list(argv)
if cwd_from:
try:
@ -250,6 +252,10 @@ class Child:
from .shell_integration import modify_shell_environ
modify_shell_environ(opts, env, self.argv)
env = {k: v for k, v in env.items() if v is not DELETE_ENV_VAR}
if self.is_clone_launch:
env['KITTY_IS_CLONE_LAUNCH'] = self.is_clone_launch
else:
env.pop('KITTY_IS_CLONE_LAUNCH', None)
return env
def fork(self) -> Optional[int]:

View File

@ -348,6 +348,7 @@ def launch(
force_target_tab: bool = False,
base_env: Optional[Dict[str, str]] = None,
active: Optional[Window] = None,
is_clone_launch: str = '',
) -> Optional[Window]:
active = active or boss.active_window_for_cwd
if active:
@ -473,7 +474,7 @@ def launch(
tab = tab_for_window(boss, opts, target_tab)
if tab is not None:
watchers = load_watch_modules(opts.watcher)
new_window: Window = tab.new_window(env=env or None, watchers=watchers or None, **kw)
new_window: Window = tab.new_window(env=env or None, watchers=watchers or None, is_clone_launch=is_clone_launch, **kw)
if opts.color:
apply_colors(new_window, opts.color)
if opts.keep_focus and active:
@ -590,7 +591,7 @@ def clone_and_launch(msg: str, window: Window) -> None:
c.opts.copy_env = False
if c.opts.type in ('clipboard', 'primary', 'background'):
c.opts.type = 'window'
serialized_env = serialize_env(c.shell, c.env or {})
is_clone_launch = serialize_env(c.shell, c.env or {})
ssh_kitten_cmdline = window.ssh_kitten_cmdline()
if ssh_kitten_cmdline:
from kittens.ssh.main import set_cwd_in_cmdline, set_env_in_cmdline, patch_cmdline
@ -599,14 +600,13 @@ def clone_and_launch(msg: str, window: Window) -> None:
set_cwd_in_cmdline(c.opts.cwd, cmdline)
c.opts.cwd = None
if c.env:
set_env_in_cmdline({'KITTY_IS_CLONE_LAUNCH': serialized_env}, cmdline)
set_env_in_cmdline({'KITTY_IS_CLONE_LAUNCH': is_clone_launch}, cmdline)
c.env = None
if c.opts.env:
for entry in reversed(c.opts.env):
patch_cmdline('env', entry, cmdline)
c.opts.env = []
else:
c.opts.env = list(c.opts.env) + ['KITTY_IS_CLONE_LAUNCH=' + serialized_env]
try:
cmdline = cmdline_of_process(c.pid)
except Exception:
@ -617,4 +617,4 @@ def clone_and_launch(msg: str, window: Window) -> None:
cmdline[0] = window.child.final_exe
if cmdline and cmdline == [window.child.final_exe] + window.child.argv[1:]:
cmdline = window.child.unmodified_argv
launch(get_boss(), c.opts, cmdline, base_env=c.env, active=window)
launch(get_boss(), c.opts, cmdline, base_env=c.env, active=window, is_clone_launch=is_clone_launch)

View File

@ -358,7 +358,8 @@ class Tab: # {{{
cwd_from: Optional[CwdRequest] = None,
cwd: Optional[str] = None,
env: Optional[Dict[str, str]] = None,
allow_remote_control: bool = False
allow_remote_control: bool = False,
is_clone_launch: str = '',
) -> Child:
check_for_suitability = True
if cmd is None:
@ -407,7 +408,7 @@ class Tab: # {{{
pwid = platform_window_id(self.os_window_id)
if pwid is not None:
fenv['WINDOWID'] = str(pwid)
ans = Child(cmd, cwd or self.cwd, stdin, fenv, cwd_from, allow_remote_control=allow_remote_control)
ans = Child(cmd, cwd or self.cwd, stdin, fenv, cwd_from, allow_remote_control=allow_remote_control, is_clone_launch=is_clone_launch)
ans.fork()
return ans
@ -431,10 +432,13 @@ class Tab: # {{{
allow_remote_control: bool = False,
marker: Optional[str] = None,
watchers: Optional[Watchers] = None,
overlay_behind: bool = False
overlay_behind: bool = False,
is_clone_launch: str = '',
) -> Window:
child = self.launch_child(
use_shell=use_shell, cmd=cmd, stdin=stdin, cwd_from=cwd_from, cwd=cwd, env=env, allow_remote_control=allow_remote_control)
use_shell=use_shell, cmd=cmd, stdin=stdin, cwd_from=cwd_from, cwd=cwd, env=env, allow_remote_control=allow_remote_control,
is_clone_launch=is_clone_launch
)
window = Window(
self, child, self.args, override_title=override_title,
copy_colors_from=copy_colors_from, watchers=watchers