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 4c0f931d6688d06df2e22d001182f6fa1b776fab
parent b39e196040623a80bf9f1a0a05c3da8523e26ee3
Author: René Wagner <rwagner@rw-net.de>
Date:   Tue,  5 Jan 2021 20:17:06 +0100

implement e[N] command

this command sends the URI of Nth link to `xdg-open` to open
the assoziated default program and pass the URI.

Diffstat:
MREADME.md | 1+
Msrc/cgmnlm.c | 23++++++++++++++---------
2 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/README.md b/README.md @@ -17,6 +17,7 @@ This project is of fork of https://git.sr.ht/~sircmpwn/gmni It includes the following modifications: - default 4 char indenting +- e[N] command to open a link in default external program (requires `xdg-open`) - colored headings & links The actual colors used depend on your terminal palette: diff --git a/src/cgmnlm.c b/src/cgmnlm.c @@ -82,6 +82,7 @@ const char *help_msg = "q\tQuit\n" "[N]\tFollow Nth link (where N is a number)\n" "u[N]\tShow URL of Nth link (where N is a number)\n" + "e[N]\tSend URL of Nth link in external default program\n" "b\tBack (in the page history)\n" "f\tForward (in the page history)\n" "H\tView all page history\n" @@ -502,8 +503,11 @@ do_prompts(const char *prompt, struct browser *browser) enum prompt_result result; fprintf(browser->tty, "%s", prompt); - size_t l = 0; + struct link *link = browser->links; + char *endptr = NULL; + int linksel = 0; char *in = NULL; + size_t l = 0; ssize_t n = getline(&in, &l, browser->tty); if (n == -1 && feof(browser->tty)) { result = PROMPT_QUIT; @@ -592,11 +596,10 @@ do_prompts(const char *prompt, struct browser *browser) result = PROMPT_AGAIN; goto exit; } + case 'e': case 'u': if (!in[1]) break; - struct link *link = browser->links; - char *endptr; - int linksel = (int)strtol(in+1, &endptr, 10); + linksel = (int)strtol(in+1, &endptr, 10); if (!endptr[0] && linksel >= 0) { while (linksel > 0 && link) { link = link->next; @@ -607,8 +610,12 @@ do_prompts(const char *prompt, struct browser *browser) fprintf(stderr, "Error: no such link.\n"); } else { fprintf(browser->tty, "=> %s\n", link->url); - result = PROMPT_AGAIN; - goto exit; + 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"); + } + fprintf(browser->tty, "\n"); } } else { fprintf(stderr, "Error: invalid argument.\n"); @@ -664,9 +671,7 @@ do_prompts(const char *prompt, struct browser *browser) goto exit; } - struct link *link = browser->links; - char *endptr; - int linksel = (int)strtol(in, &endptr, 10); + linksel = (int)strtol(in, &endptr, 10); if ((endptr[0] == '\0' || endptr[0] == '|') && linksel >= 0) { while (linksel > 0 && link) { link = link->next;