mirror of
https://github.com/kovidgoyal/kitty
synced 2026-06-08 22:28:24 +02:00
Finish porting +open single instance CLI parsing
This commit is contained in:
@@ -12,6 +12,7 @@
|
|||||||
typedef struct CLIOptions {
|
typedef struct CLIOptions {
|
||||||
const char *session, *instance_group;
|
const char *session, *instance_group;
|
||||||
bool single_instance, version_requested, wait_for_single_instance_window_close;
|
bool single_instance, version_requested, wait_for_single_instance_window_close;
|
||||||
|
int open_url_count; char **open_urls;
|
||||||
} CLIOptions;
|
} CLIOptions;
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -369,7 +369,13 @@ static void
|
|||||||
handle_fast_commandline(int argc, char *argv[]) {
|
handle_fast_commandline(int argc, char *argv[]) {
|
||||||
char current_option_expecting_argument[128] = {0};
|
char current_option_expecting_argument[128] = {0};
|
||||||
CLIOptions opts = {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];
|
const char *arg = argv[i];
|
||||||
if (current_option_expecting_argument[0]) {
|
if (current_option_expecting_argument[0]) {
|
||||||
handle_option_value:
|
handle_option_value:
|
||||||
@@ -380,7 +386,13 @@ handle_option_value:
|
|||||||
}
|
}
|
||||||
current_option_expecting_argument[0] = 0;
|
current_option_expecting_argument[0] = 0;
|
||||||
} else {
|
} 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
|
if (arg[1] == '-') { // long opt
|
||||||
const char *equal = strchr(arg, '=');
|
const char *equal = strchr(arg, '=');
|
||||||
if (equal == NULL) {
|
if (equal == NULL) {
|
||||||
|
|||||||
@@ -226,7 +226,9 @@ talk_to_instance(int s, struct sockaddr_un *server_addr, int argc, char *argv[],
|
|||||||
}
|
}
|
||||||
w("}");
|
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\":");
|
w(",\"notify_on_os_window_death\":");
|
||||||
int notify_socket = -1;
|
int notify_socket = -1;
|
||||||
|
|||||||
Reference in New Issue
Block a user