surf

A surf web browser [kocotian build]
git clone git://git.kocotian.pl/surf.git
Log | Files | Refs | README | LICENSE

commit b10a665f81ce74a7ac947ad1c65cc71920cfcaef
parent 532e6326e4b2ab0bfd43f5e8df13d3f7c3204b3f
Author: kocotian <kocotian@kocotian.pl>
Date:   Tue, 22 Dec 2020 18:12:22 +0100

bookmarking, yanking url

Diffstat:
Mconfig.def.h | 46++++++++++++++++++++++++++++++++++++++++++----
Mpatches/surf-bookmarks-20170722-723ff26.diff | 0
Msurf.c | 2+-
3 files changed, 43 insertions(+), 5 deletions(-)

diff --git a/config.def.h b/config.def.h @@ -82,15 +82,27 @@ static int winsize[] = { 800, 600 }; static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | WEBKIT_FIND_OPTIONS_WRAP_AROUND; -#define PROMPT_GO "Go:" -#define PROMPT_FIND "Find:" +#define PROMPT_GO "" +#define PROMPT_FIND "/ " + +/* GO(readprop, setprop, prompt)*/ +#define GO(r, s, p) { \ + .v = (const char *[]){ "/bin/sh", "-c", \ + "prop=\"$(printf '%b' \"$(xprop -id $1 $2 " \ + "| sed \"s/^$2(STRING) = //;s/^\\\"\\(.*\\)\\\"$/\\1/\" && cat ~/.config/surf/bookmarks)\" " \ + "| dmenu -l 20 -p \"$4\" -w $1)\" && " \ + "xprop -id $1 -f $3 8s -set $3 \"$prop\"", \ + "surf-setprop", winid, r, s, p, NULL \ + } \ +} /* SETPROP(readprop, setprop, prompt)*/ #define SETPROP(r, s, p) { \ .v = (const char *[]){ "/bin/sh", "-c", \ "prop=\"$(printf '%b' \"$(xprop -id $1 $2 " \ "| sed \"s/^$2(STRING) = //;s/^\\\"\\(.*\\)\\\"$/\\1/\")\" " \ - "| dmenu -p \"$4\" -w $1)\" && xprop -id $1 -f $3 8s -set $3 \"$prop\"", \ + "| dmenu -p \"$4\" -w $1)\" && " \ + "xprop -id $1 -f $3 8s -set $3 \"$prop\"", \ "surf-setprop", winid, r, s, p, NULL \ } \ } @@ -126,6 +138,29 @@ static WebKitFindOptions findopts = WEBKIT_FIND_OPTIONS_CASE_INSENSITIVE | "xprop -id $1 -f $0 8s -set $0 \"$prop\"", \ p, winid, NULL } } +/* BM_ADD(readprop) */ +#define BM_ADD(r) {\ + .v = (const char *[]){ "/bin/sh", "-c", \ + "(echo $(xprop -id $0 $1) | cut -d '\"' -f2 " \ + "| sed 's/.*https*:\\/\\/\\(www\\.\\)\\?//' && cat ~/.config/surf/bookmarks) " \ + "| awk '!seen[$0]++' > ~/.config/surf/bookmarks.tmp && " \ + "mv ~/.config/surf/bookmarks.tmp ~/.config/surf/bookmarks && " \ + "notify-send \"📑 Bookmark added\" \"$(sed 1q ~/.config/surf/bookmarks)\"", \ + winid, r, NULL \ + } \ +} + +/* COPYURL(readprop) */ +#define COPYURL(prop) {\ + .v = (const char *[]){ "/bin/sh", "-c", \ + "echo $(xprop -id $0 $1) | cut -d '\"' -f2" \ + "> /tmp/surfurl && cat /tmp/surfurl" \ + "| xclip -selection clipboard && " \ + "notify-send '📋 Copied to clipboard:' \"$(cat /tmp/surfurl)\"", \ + winid, prop, NULL \ + } \ +} + /* styles */ /* * The iteration will stop at the first match, beginning at the beginning of @@ -155,9 +190,12 @@ static SiteSpecific certs[] = { */ static Key keys[] = { /* modifier keyval function arg */ - { MODKEY, GDK_KEY_g, spawn, SETPROP("_SURF_URI", "_SURF_GO", PROMPT_GO) }, { MODKEY, GDK_KEY_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) }, { MODKEY, GDK_KEY_slash, spawn, SETPROP("_SURF_FIND", "_SURF_FIND", PROMPT_FIND) }, + { MODKEY, GDK_KEY_y, spawn, COPYURL("_SURF_URI") }, + { MODKEY, GDK_KEY_m, spawn, BM_ADD("_SURF_URI") }, + + { MODKEY, GDK_KEY_g, spawn, GO("_SURF_URI", "_SURF_GO", PROMPT_GO) }, { 0, GDK_KEY_Escape, stop, { 0 } }, { MODKEY, GDK_KEY_c, stop, { 0 } }, diff --git a/patches/surf-bookmarks-20170722-723ff26.diff b/patches/surf-bookmarks-20170722-723ff26.diff diff --git a/surf.c b/surf.c @@ -2216,7 +2216,7 @@ main(int argc, char *argv[]) if (startgo) { /* start directly into GO prompt */ - Arg a = (Arg)SETPROP("_SURF_URI", "_SURF_GO", PROMPT_GO); + Arg a = (Arg)GO("_SURF_URI", "_SURF_GO", PROMPT_GO); spawn(c, &a); }