This allows to remove bookmark for bookmark file.
.TP
.BI "bookmark-add [" TAGS "], bma [" TAGS ]
Save the current opened uri with \fITAGS\fP to the bookmark file.
+.TP
+.BI "bookmark-remove [" URI "], bmr [" URI ]
+Removes all bookmarks for given \fIURI\fP or if not given the current opened
+page.
.SS Misc
.TP
return false;
}
+gboolean bookmark_remove(const char *uri)
+{
+ char **lines, *line, *p;
+ int len, i;
+ GString *new;
+ gboolean removed = false;
+
+ if (!uri) {
+ return false;
+ }
+
+ lines = util_get_lines(vb.files[FILES_BOOKMARK]);
+ if (lines) {
+ new = g_string_new(NULL);
+ len = g_strv_length(lines) - 1;
+ for (i = 0; i < len; i++) {
+ line = lines[i];
+ g_strstrip(line);
+ /* ignore the bookmark tags and test only the uri */
+ if ((p = strchr(line, ' '))) {
+ *p = '\0';
+ if (!strcmp(uri, line)) {
+ removed = true;
+ continue;
+ } else {
+ /* reappend the tags */
+ *p = ' ';
+ }
+ }
+ if (!strcmp(uri, line)) {
+ removed = true;
+ continue;
+ }
+ g_string_append_printf(new, "%s\n", line);
+ }
+ g_strfreev(lines);
+ g_file_set_contents(vb.files[FILES_BOOKMARK], new->str, -1, NULL);
+ g_string_free(new, true);
+ }
+
+ return removed;
+}
+
/**
* Retrieves all bookmark uri matching the given space separated tags string.
* Don't forget to free the returned list.
#define _BOOKMARK_H
gboolean bookmark_add(const char *uri, const char *tags);
+gboolean bookmark_remove(const char *uri);
GList *bookmark_get_by_tags(const char *tags);
#endif /* end of include guard: _BOOKMARK_H */
{"hist-prev", NULL, command_history, {1}},
{"run", NULL, command_run_multi, {0}},
{"bookmark-add", "bma", command_bookmark, {1}},
+ {"bookmark-remove", "bmr", command_bookmark, {0}},
{"eval", "e", command_eval, {0}},
{"editor", NULL, command_editor, {0}},
{"next", "n", command_nextprev, {0}},
{
vb_set_mode(VB_MODE_NORMAL, false);
- if (bookmark_add(GET_URI(), arg->s)) {
+ if (!arg->i) {
+ if (bookmark_remove(arg->s ? arg->s : GET_URI())) {
+ vb_echo_force(VB_MSG_NORMAL, false, "Bookmark removed");
+
+ return true;
+ }
+ } else if (bookmark_add(GET_URI(), arg->s)) {
vb_echo_force(VB_MSG_NORMAL, false, "Bookmark added");
return true;
}
+
return false;
}