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 5d09ed3ce45ba338716b70731fff7e921688c67c
parent ba32ed8883ec6e8d03d10f1b4e2cc5afd16a4f14
Author: Ondřej Fiala <temp.xanomes@volny.cz>
Date:   Wed, 12 Jan 2022 19:04:35 +0100

gmnlm: add optional custom bookmark titles

It is often useful to title a bookmark differently from how the page's
author titled it.

Diffstat:
Msrc/gmnlm.c | 14+++++---------
1 file changed, 5 insertions(+), 9 deletions(-)

diff --git a/src/gmnlm.c b/src/gmnlm.c @@ -94,7 +94,7 @@ const char *help_msg = "f[N]\t\tJump forward N entries in history (N is optional, default 1)\n" "u\t\tNavigate one path element up\n" "H\t\tView all page history\n" - "m\t\tSave bookmark\n" + "m [title]\t\tSave bookmark\n" "M\t\tBrowse bookmarks\n" "k\t\tRemove bookmark for current page\n" "r\t\tReload the page\n" @@ -174,7 +174,7 @@ trim_ws(char *in) } static void -save_bookmark(struct browser *browser) +save_bookmark(struct browser *browser, const char *title) { char *path_fmt = get_data_pathfmt(); static char path[PATH_MAX+1]; @@ -198,11 +198,6 @@ save_bookmark(struct browser *browser) return; } - char *title = browser->page_title; - if (title) { - title = trim_ws(browser->page_title); - } - fprintf(f, "=> %s%s%s\n", browser->plain_url, title ? " " : "", title ? title : ""); fclose(f); @@ -712,8 +707,9 @@ do_prompts(const char *prompt, struct browser *browser) result = PROMPT_AGAIN; goto exit; case 'm': - if (in[1]) break; - save_bookmark(browser); + if (in[1] != '\0' && !isspace(in[1])) break; + char *title = in[1] ? &in[1] : browser->page_title; + save_bookmark(browser, trim_ws(title)); result = PROMPT_AGAIN; goto exit; case 'k':