diff --git a/src/config/options.inc b/src/config/options.inc index 9c2c7641..b3810823 100644 --- a/src/config/options.inc +++ b/src/config/options.inc @@ -852,21 +852,32 @@ static union option_info config_options_info[] = { "link and tab menu will have a submenu of items for each " "rule.\n" "\n" - "Note, this is mostly useful for launching graphical viewers, " - "since there is no support for releasing the terminal while " - "the command runs. The action and submenus are also available " - "by binding keys to the frame-external-command, the " - "link-external-command, and the tab-external-command " - "actions.")), + "The action and submenus are also available by binding keys " + "to the frame-external-command, the link-external-command, " + "and the tab-external-command actions.\n" + "\n" + "Commands run in the background by default: elinks is still " + "active, and they do not receive standard input. " + "The \"foreground\" suboption reverses this behaviour: " + "the command receives standard input " + "and elinks is blocked.\n")), - INIT_OPT_STRING("document.uri_passing", NULL, - "_template_", 0, "", - N_("A rule for passing URI to an external command. " + INIT_OPT_TREE("document.uri_passing", NULL, + "_template_", 0, + N_("A rule for passing URI to an external command.")), + + INIT_OPT_STRING("document.uri_passing._template_", NULL, + "command", 0, "", + N_("The external command. " "The format is:\n" "%c in the string means the current URL\n" "%% in the string means '%'\n" "Do _not_ put single- or double-quotes around %c.")), + INIT_OPT_BOOL("document.uri_passing._template_", NULL, + "foreground", 0, 0, + N_("Run command in the foreground.")), + /* Keep options in alphabetical order. */ diff --git a/src/dialogs/menu.c b/src/dialogs/menu.c index 13ef4d28..97934362 100644 --- a/src/dialogs/menu.c +++ b/src/dialogs/menu.c @@ -762,8 +762,9 @@ static void do_pass_uri_to_command(struct terminal *term, void *command_, void *xxx) { char *command = command_; + int block = command[0] == 'b' ? TERM_EXEC_BG : TERM_EXEC_FG; - exec_on_terminal(term, command, "", TERM_EXEC_BG); + exec_on_terminal(term, command + 1, "", block); mem_free(command); } @@ -820,7 +821,7 @@ pass_uri_to_command(struct session *ses, struct document_view *doc_view, NULL); enum pass_uri_type type = which_type; struct menu_item *items; - struct option *option; + struct option *option, *sub; struct uri *uri; int commands = 0; @@ -856,7 +857,8 @@ pass_uri_to_command(struct session *ses, struct document_view *doc_view, } foreach (option, *tree) { - char *text, *data; + char *text, *command, *data; + int block; if (!strcmp(option->name, "_template_")) continue; @@ -864,11 +866,26 @@ pass_uri_to_command(struct session *ses, struct document_view *doc_view, text = stracpy(option->name); if (!text) continue; - data = format_command(option->value.string, uri); + command = NULL; + block = 0; + + foreach (sub, *option->value.tree) { + if (!strcmp(sub->name, "command")) + command = sub->value.string; + if (!strcmp(sub->name, "foreground")) + block = sub->value.number; + } + + if (!command) + continue; + + data = format_command(command, uri); if (!data) { mem_free(text); continue; } + insert_in_string(&data, 0, " ", 1); + data[0] = block ? 'f' : 'b'; add_to_menu(&items, text, NULL, ACT_MAIN_NONE, do_pass_uri_to_command, data, 0);