diff --git a/kitty/launcher/launcher.h b/kitty/launcher/launcher.h index d30476a0c..29047e279 100644 --- a/kitty/launcher/launcher.h +++ b/kitty/launcher/launcher.h @@ -12,6 +12,7 @@ typedef struct CLIOptions { const char *session, *instance_group; bool single_instance, version_requested, wait_for_single_instance_window_close; + int open_url_count; char **open_urls; } CLIOptions; diff --git a/kitty/launcher/main.c b/kitty/launcher/main.c index e7855c52b..9330ef627 100644 --- a/kitty/launcher/main.c +++ b/kitty/launcher/main.c @@ -369,7 +369,13 @@ static void handle_fast_commandline(int argc, char *argv[]) { char current_option_expecting_argument[128] = {0}; CLIOptions opts = {0}; - for (int i = 1; i < argc; i++) { + int first_arg = 1; + if (argc > 1 && strcmp(argv[1], "+open") == 0) { + first_arg = 2; + } else if (argc > 2 && strcmp(argv[1], "+") == 0 && strcmp(argv[2], "open") == 0) { + first_arg = 3; + } + for (int i = first_arg; i < argc; i++) { const char *arg = argv[i]; if (current_option_expecting_argument[0]) { handle_option_value: @@ -380,7 +386,13 @@ handle_option_value: } current_option_expecting_argument[0] = 0; } else { - if (!arg || !arg[0] || !arg[1] || arg[0] != '-' || strcmp(arg, "--") == 0) break; + if (!arg || !arg[0] || !arg[1] || arg[0] != '-' || strcmp(arg, "--") == 0) { + if (first_arg > 1) { + opts.open_urls = argv + i; + opts.open_url_count = argc - i; + } + break; + } if (arg[1] == '-') { // long opt const char *equal = strchr(arg, '='); if (equal == NULL) { diff --git a/kitty/launcher/single-instance.c b/kitty/launcher/single-instance.c index 94e86194f..1b2d76061 100644 --- a/kitty/launcher/single-instance.c +++ b/kitty/launcher/single-instance.c @@ -226,7 +226,9 @@ talk_to_instance(int s, struct sockaddr_un *server_addr, int argc, char *argv[], } w("}"); - w(",\"cmdline_args_for_open\":[]"); + w(",\"cmdline_args_for_open\":"); + if (opts->open_url_count) write_json_string_array(&output, opts->open_url_count, opts->open_urls); + else w("[]"); w(",\"notify_on_os_window_death\":"); int notify_socket = -1;