diff --git a/kitty/launcher/main.c b/kitty/launcher/main.c index f9bb88450..9714c7f0b 100644 --- a/kitty/launcher/main.c +++ b/kitty/launcher/main.c @@ -36,10 +36,6 @@ cleanup_free(void *p) { #define RAII_ALLOC(type, name, initializer) __attribute__((cleanup(cleanup_free))) type *name = initializer static bool being_tested = false; -// The full command line to re-exec on --detach: for +kitten panel the -// cli_spec's original_argv starts at "panel", not at the executable. -static int full_argc = 0; -static char **full_argv = NULL; #ifndef __FreeBSD__ static bool @@ -403,8 +399,11 @@ offset_for_plus_subcommand(int argc, char **argv, const char *name) { return offset; } +// full_argc/full_argv are the complete command line, used to re-exec on +// --detach. They differ from cli_spec->original_argv for +kitten panel, where +// original_argv starts at "panel", not at the executable. static void -handle_fast_commandline(CLISpec *cli_spec, const char *instance_group_prefix) { +handle_fast_commandline(CLISpec *cli_spec, const char *instance_group_prefix, int full_argc, char **full_argv) { CLIOptions opts = {0}; RAII_CLISpec(subcommand_cli_spec); #define swap_cli_spec \ @@ -543,7 +542,7 @@ delegate_to_kitten_if_possible(int argc, char **argv, char *exe_dir) { if (strcmp(kitten, "panel") == 0) { offset++; CLISpec t = {.original_argv = argv + offset, .original_argc = argc - offset}; - handle_fast_commandline(&t, "panel"); + handle_fast_commandline(&t, "panel", argc, argv); return true; } } @@ -626,12 +625,10 @@ main(int argc_, char *argv_[], char *envp[]) { #endif (void)read_full_file; RAII_CLISpec(cli_spec); - full_argc = argva.count; - full_argv = argva.argv; bool handle_fast_commandline_called = delegate_to_kitten_if_possible(argva.count, argva.argv, exe_dir); bool ok = parse_and_check_kitty_cli(&cli_spec, argva.count, argva.argv); if (!ok) return 1; - if (!handle_fast_commandline_called) handle_fast_commandline(&cli_spec, NULL); + if (!handle_fast_commandline_called) handle_fast_commandline(&cli_spec, NULL, argva.count, argva.argv); int ret = 0; char lib[PATH_MAX + 1] = {0}; if (KITTY_LIB_PATH[0] == '/') { diff --git a/kitty_tests/options.py b/kitty_tests/options.py index 4652719bc..0721e3abf 100644 --- a/kitty_tests/options.py +++ b/kitty_tests/options.py @@ -360,8 +360,12 @@ def launcher(self): t('+open -1 --help', argv=['+open', '-1', '--help']) si('+open -1 moose', argv=[kexe, '+open', '-1', 'moose'], open_urls=['moose']) si('+open -1 --instance-group=g x y', instance_group='g', open_urls=['x', 'y']) - dt('--detach --session=moose --detached-log=xyz', detached_log='xyz', session='moose', - detach_exec_argv=[kexe, '--detach', '--session=moose', '--detached-log=xyz']) + dt( + '--detach --session=moose --detached-log=xyz', + detached_log='xyz', + session='moose', + detach_exec_argv=[kexe, '--detach', '--session=moose', '--detached-log=xyz'], + ) pn('+kitten panel -1 --edge=left', edge='left') dt('+kitten panel --detach --edge=top', detach_exec_argv=[kexe, '+kitten', 'panel', '--detach', '--edge=top']) dt('+ kitten panel --detach', detach_exec_argv=[kexe, '+', 'kitten', 'panel', '--detach'])