diff --git a/src/gmnlm.c b/src/gmnlm.c
index 6a27f53bb31f0084b0ba687f5de94628ad494774..6ebffa64d42f52cd1a75c320fa33d2946bbbfdd7 100644
--- a/src/gmnlm.c
+++ b/src/gmnlm.c
@@ -86,12 +86,12 @@ const char *help_msg =
"The following commands are available:\n\n"
"<Enter>\t\tread more lines (if available)\n"
"<url>\t\tgo to url\n"
- "[N]\t\tFollow Nth link (where N is a number)\n"
- "p[N]\t\tPrint URL of Nth link (where N is a number)\n"
- "e[N]\t\tSend URL of Nth link or current URL when N is ommited to external default program\n"
- "t[N]\t\tDownload content of Nth link to a temporary file\n"
- "b[N]\t\tJump back N entries in history, N is optional, default 1\n"
- "f[N]\t\tJump forward N entries in history, N is optional, default 1\n"
+ "[N]\t\tFollow Nth link\n"
+ "p[N]\t\tPrint URL of Nth link\n"
+ "e[N]\t\tSend URL of current page or Nth link to external default program (N is optional)\n"
+ "t[N]\t\tDownload content of current page or Nth link to a temporary file (N is optional)\n"
+ "b[N]\t\tJump back N entries in history (N is optional, default 1)\n"
+ "f[N]\t\tJump forward N entries in history (N is optional, default 1)\n"
"u\t\tone path element up\n"
"H\t\tView all page history\n"
"m\t\tSave bookmark\n"
@@ -106,6 +106,8 @@ "|<prog>\t\tPipe page into program\n"
"[N]|<prog>\tPipe content of Nth link into program\n"
"a\t\ttoggle usage of alt text instead of preformatted text\n"
"q\t\tQuit\n"
+ "\n"
+ "[N] must be replaced with a number > 0\n"
"\n"
;
@@ -668,7 +670,7 @@ result = PROMPT_ANSWERED;
goto exit;
case 'u':;
int keep = 0;
- int len = strlen(browser->plain_url);
+ int len = strlen(browser->plain_url);
for (int i=0; i<len; i++)
{
// ignore trailing / on uri path
@@ -744,50 +746,44 @@ case 'e':
case 'p':
case 't':
if (!in[1]) {
- if (in[0] == 'e') {
- snprintf(url, sizeof(url), "xdg-open %s", browser->plain_url);
- if ( !system(url) ) fprintf(browser->tty, "Link send to xdg-open\n");
- goto exit;
- } else {
- break;
+ strncpy(&url[0], browser->plain_url, sizeof(url)-1);
+ } else {
+ linksel = (int)strtol(in+1, &endptr, 10);
+ if (!endptr[0] && linksel >= 0) {
+ while (linksel > 0 && link) {
+ link = link->next;
+ --linksel;
+ }
+ if (!link) {
+ fprintf(stderr, "Error: no such link.\n");
+ } else {
+ strncpy(&url[0], link->url, sizeof(url)-1);
+ }
}
}
- linksel = (int)strtol(in+1, &endptr, 10);
- if (!endptr[0] && linksel >= 0) {
- while (linksel > 0 && link) {
- link = link->next;
- --linksel;
+ if (url[0]) {
+ fprintf(browser->tty, "=> %s\n", url);
+ if (in[0] == 'e') {
+ char target[2048] = {0};
+ snprintf(target, sizeof(target), "xdg-open %s", url);
+ if ( !system(target) ) fprintf(browser->tty, "Link send to xdg-open\n");
}
-
- if (!link) {
- fprintf(stderr, "Error: no such link.\n");
- } else {
- fprintf(browser->tty, "=> %s\n", link->url);
- if (in[0] == 'e') {
- snprintf(url, sizeof(url), "xdg-open %s", link->url);
- if ( !system(url) ) fprintf(browser->tty, "Link send to xdg-open\n");
- }
- if (in[0] == 't') {
- struct gemini_response resp;
- strncpy(&url[0], browser->plain_url, sizeof(link->url)-1);
- set_url(browser, link->url, &browser->history);
- // XXX: may affect history, do we care?
- enum gemini_result res = do_requests(browser, &resp);
- if (res != GEMINI_OK) {
- fprintf(stderr, "Error: %s\n",
- gemini_strerr(res, &resp));
- } else {
- char tempfile[] = "/tmp/cgmnlm_XXXXXX";
- mkstemp(tempfile);
- download_resp(browser->tty, resp, tempfile, link->url);
- }
- gemini_response_finish(&resp);
- set_url(browser, url, NULL);
+ if (in[0] == 't') {
+ struct gemini_response resp;
+ set_url(browser, url, &browser->history);
+ enum gemini_result res = do_requests(browser, &resp);
+ if (res != GEMINI_OK) {
+ fprintf(stderr, "Error: %s\n",
+ gemini_strerr(res, &resp));
+ } else {
+ char tempfile[] = "/tmp/cgmnlm_XXXXXXXX";
+ mkstemp(tempfile);
+ download_resp(browser->tty, resp, tempfile, url);
}
- fprintf(browser->tty, "\n");
+ gemini_response_finish(&resp);
+ set_url(browser, url, NULL);
}
- } else {
- fprintf(stderr, "Error: invalid argument.\n");
+ fprintf(browser->tty, "\n");
}
result = PROMPT_AGAIN;
goto exit;