diff --git a/src/gmnlm.c b/src/gmnlm.c
index 9efe3e231d445d55ea43d444a72eaa79f595ac76..37b4db277d8fcd961eb1746294724783e638109c 100644
--- a/src/gmnlm.c
+++ b/src/gmnlm.c
@@ -87,11 +87,11 @@ "<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\t\tSend current URL of browser to external default program\n"
- "e[N]\t\tSend URL of Nth link in external default program\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"
+ "u\t\tone path element up\n"
"H\t\tView all page history\n"
"m\t\tSave bookmark\n"
"M\t\tBrowse bookmarks\n"
@@ -623,6 +623,7 @@ goto exit;
}
in[n - 1] = 0; // Remove LF
+ char url[1024] = {0};
int r;
switch (in[0]) {
case '\0':
@@ -664,6 +665,22 @@ }
set_url(browser, browser->history->url, NULL);
result = PROMPT_ANSWERED;
goto exit;
+ case 'u':;
+ int keep = 0;
+ int len = strlen(browser->plain_url);
+ for (int i=0; i<len; i++)
+ {
+ // ignore trailing / on uri path
+ if (browser->plain_url[i] == '/' && i != len-1) {
+ keep = i;
+ }
+ }
+ if (keep > 9) {
+ strncpy(url , browser->plain_url, keep+1);
+ set_url(browser, url, &browser->history);
+ }
+ result = PROMPT_ANSWERED;
+ goto exit;
case 'H':
if (in[1]) break;
struct history *cur = browser->history;
@@ -723,9 +740,8 @@ case 'p':
case 't':
if (!in[1]) {
if (in[0] == 'e') {
- char xdgopen[4096];
- snprintf(xdgopen, sizeof(xdgopen), "xdg-open %s", browser->plain_url);
- if ( !system(xdgopen) ) fprintf(browser->tty, "Link send to xdg-open\n");
+ 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;
@@ -743,13 +759,11 @@ fprintf(stderr, "Error: no such link.\n");
} else {
fprintf(browser->tty, "=> %s\n", link->url);
if (in[0] == 'e') {
- char xdgopen[4096];
- snprintf(xdgopen, sizeof(xdgopen), "xdg-open %s", link->url);
- if ( !system(xdgopen) ) fprintf(browser->tty, "Link send to xdg-open\n");
+ 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;
- char url[1024] = {0};
strncpy(&url[0], browser->plain_url, sizeof(link->url)-1);
set_url(browser, link->url, &browser->history);
// XXX: may affect history, do we care?
@@ -785,7 +799,6 @@ goto exit;
case 'd':
if (in[1] != '\0' && !isspace(in[1])) break;
struct gemini_response resp;
- char url[1024] = {0};
strncpy(&url[0], browser->plain_url, sizeof(url)-1);
// XXX: may affect history, do we care?
enum gemini_result res = do_requests(browser, &resp);
@@ -831,7 +844,6 @@
if (!link) {
fprintf(stderr, "Error: no such link.\n");
} else if (endptr[0] == '|') {
- char url[1024] = {0};
struct gemini_response resp;
strncpy(url, browser->plain_url, sizeof(url) - 1);
set_url(browser, link->url, &browser->history);