cgmnlm

Unnamed repository; edit this file 'description' to name the repository.
git clone git://code.clttr.info/cgmnlm.git
Log | Files | Refs | README | LICENSE

commit 18ead2644a8c525d1d3bbc729d9ccd9aa7e0d63c
parent 4dd50ac07e82dfc1785f98a3535109e2d738029d
Author: René Wagner <rwa@clttr.info>
Date:   Mon, 28 Jun 2021 22:34:26 +0200

add 'u' command to navigate one path element up

Diffstat:
Msrc/gmnlm.c | 34+++++++++++++++++++++++-----------
1 file changed, 23 insertions(+), 11 deletions(-)

diff --git a/src/gmnlm.c b/src/gmnlm.c @@ -87,11 +87,11 @@ const char *help_msg = "<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 @@ do_prompts(const char *prompt, struct browser *browser) } in[n - 1] = 0; // Remove LF + char url[1024] = {0}; int r; switch (in[0]) { case '\0': @@ -664,6 +665,22 @@ do_prompts(const char *prompt, struct browser *browser) 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 @@ do_prompts(const char *prompt, struct browser *browser) 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 @@ do_prompts(const char *prompt, struct browser *browser) } 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 @@ do_prompts(const char *prompt, struct browser *browser) 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 @@ do_prompts(const char *prompt, struct browser *browser) 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);