Hi Markus, First of all, I have to confess (*glups*) that I am not a programmer, just a beginner enjoying quality software and trying to learn from that. For that, suckless tools and software help a lot due to the clarity of the code.
Le dimanche 15 mars 2015 à 01:12:19, Markus Teich a écrit : > Sébastien Poher wrote: > > I've add cariage return so that visited URIs are not put one after one in > > history file but each one on a new line. > > > + FILE *f; > > + f = fopen(historyfile, "a+"); > > + fprintf(f, "\n%s", u); > > + fclose(f); > > You should check if the file could be opened. Also you can replace the > suckless-less printf function with two calls to fputs, which don't have to > parse > a formatstring: > > if((f = fopen(historyfile, "a+"))) { > fputs(u, f); > fputs("\n", f); > fclose(f); > } As I mentionned above, I am not, at the moment at least, able to understand the inherent differences between those two functions, so I'll rely on your code. > > Instead of using the original version, I've adapted the function in the same > > vein of the bookmarking patch so that one can browse its history from dmenu > > by > > hiting C+S+h keys. > > I think having another shortcut to open a URL is superfluous. I changed ctrl-g > to also display the history (most recent entry topmost). Also I use a search > history and therefore split the SETPROP define into SETURI and SETSEARCH: > > #define SETURI { \ > .v = (char *[]){ "/bin/sh", "-c", \ > "prop=\"`xprop -id $0 _SURF_URI" \ > " | cut -d '\"' -f 2" \ > " | tac - \"${HOME}/.surf/history\"" \ > " | awk '!x[$0]++'" \ > " | dmenu -i -l 10`\"" \ > " && xprop -id $0 -f _SURF_GO 8s -set _SURF_GO \"$prop\"", \ > winid, NULL \ > } \ > } > > #define SETSEARCH { \ > .v = (char *[]){ "/bin/sh", "-c", \ > "prop=\"`xprop -id $0 _SURF_FIND" \ > " | cut -d '\"' -f 2" \ > " | tac - \"${HOME}/.surf/searches\"" \ > " | awk '!x[$0]++'" \ > " | xargs -0 printf %b" \ > " | dmenu -i -l 10`\"" \ > " && xprop -id $0 -f _SURF_FIND 8s -set _SURF_FIND \"$prop\"" \ > " && echo \"$prop\" >> \"${HOME}/.surf/searches\"", \ > winid, NULL \ > } \ > } > > In the SETURI call the `xargs` part is missing in the pipeline, since my > history > is already >2MiB and after too many characters the commandline call generated > by > xargs becomes too large for the shell to handle. Without the `xargs` all the > data is passed over stdin and stdout and the commandlines always stay in O(1) > and don't depend on the length of the history file. BEWARE: The person > introducing this `xargs` call is convinced it is necessary, however I did not > run into any case where it breaks when leaving it out. Thanks for that, that's a clean way to handle both history and searches and it works well. The only problem I have is that it messes with the bookmarks patch that uses SETPROP, so I was thinking about something like: #define SETURI { \ .v = (char *[]){ "/bin/sh", "-c", \ "prop=\"`xprop -id $0 _SURF_URI" \ " | cut -d '\"' -f 2" \ " | tac - \"${HOME}/.surf/bookmarks\" \"${HOME}/.surf/history\"" \ " | awk '!x[$0]++'" \ " | dmenu -i -l 10`\"" \ " && xprop -id $0 -f _SURF_GO 8s -set _SURF_GO \"$prop\"", \ winid, NULL \ } \ } So that one can have access to its bookmarks at the top of the dmenu list as well as its history whithout the need of a superfluous shortcut. > I also have a script to deduplicate the history files, which I run regularly: > > cd ~/.surf > > du -h history > tac history | awk '!x[$0]++' | tac >history.$$ > cp history.$$ history > rm -f history.$$ > du -h history > > du -h searches > tac searches | awk '!x[$0]++' | tac >history.$$ > cp history.$$ searches > rm -f history.$$ > du -h searches > > I also changed tabbed's SETPROP, so it displays a list of all open tabs first, > followed by the history (most recent entry topmost) as above. Now with > MODKEY+t > (tabbed) you can either switch to an already opened tab, open a new tab with a > URL already in the history or open a new tab with a changed URL from history > or > a completely new URL all with the help of dmenu and it's awesome filtering. > > #define SETPROP(p) { \ > .v = (char *[]){ "/bin/sh", "-c", \ > "prop=\"`xwininfo -children -id $1 | grep '^ 0x'" \ > " | sed -e's@^ *\\(0x[0-9a-f]*\\) \"\\([^\"]*\\)\".*@\\1 \\2@'" \ > " | tac - \"${HOME}/.$2/history\"" \ > " | awk '!x[$0]++'" \ > " | xargs -0 printf %b | dmenu -l 10`\"" \ > " && xprop -id $1 -f $0 8s -set $0 \"$prop\"", \ > p, winid, clientbin, NULL \ > } \ > } > > I hope this is useful to you. It is indeed, I'll will try that. Thanks a lot. I'va attached the patch that sums up all your comments. Sincerely, -- Sébastien Poher www.volted.net Aidez-nous à défendre la liberté du logiciel: http://www.fsf.org/register_form?referrer=11902
diff --git a/config.def.h b/config.def.h index a1ab211..9f1de5f 100644 --- a/config.def.h +++ b/config.def.h @@ -16,6 +16,7 @@ static gfloat zoomlevel = 1.0; /* Default zoom level */ /* Soup default features */ static char *cookiefile = "~/.surf/cookies.txt"; +static char *historyfile = "~/.surf/history"; static char *cookiepolicies = "Aa@"; /* A: accept all; a: accept nothing, @: accept no third party */ static char *cafile = "/etc/ssl/certs/ca-certificates.crt"; @@ -35,12 +36,30 @@ static Bool loadimages = TRUE; static Bool hidebackground = FALSE; static Bool allowgeolocation = TRUE; -#define SETPROP(p, q) { \ - .v = (char *[]){ "/bin/sh", "-c", \ - "prop=\"`xprop -id $2 $0 | cut -d '\"' -f 2 | xargs -0 printf %b | dmenu`\" &&" \ - "xprop -id $2 -f $1 8s -set $1 \"$prop\"", \ - p, q, winid, NULL \ - } \ +#define SETURI { \ + .v = (char *[]){ "/bin/sh", "-c", \ + "prop=\"`xprop -id $0 _SURF_URI" \ + " | cut -d '\"' -f 2" \ + " | tac - \"${HOME}/.surf/history\"" \ + " | awk '!x[$0]++'" \ + " | dmenu -i -l 10`\"" \ + " && xprop -id $0 -f _SURF_GO 8s -set _SURF_GO \"$prop\"", \ + winid, NULL \ + } \ +} + +#define SETSEARCH { \ + .v = (char *[]){ "/bin/sh", "-c", \ + "prop=\"`xprop -id $0 _SURF_FIND" \ + " | cut -d '\"' -f 2" \ + " | tac - \"${HOME}/.surf/searches\"" \ + " | awk '!x[$0]++'" \ + " | xargs -0 printf %b" \ + " | dmenu -i -l 10`\"" \ + " && xprop -id $0 -f _SURF_FIND 8s -set _SURF_FIND \"$prop\"" \ + " && echo \"$prop\" >> \"${HOME}/.surf/searches\"", \ + winid, NULL \ + } \ } /* DOWNLOAD(URI, referer) */ @@ -110,9 +129,9 @@ static Key keys[] = { { MODKEY, GDK_o, source, { 0 } }, { MODKEY|GDK_SHIFT_MASK,GDK_o, inspector, { 0 } }, - { MODKEY, GDK_g, spawn, SETPROP("_SURF_URI", "_SURF_GO") }, - { MODKEY, GDK_f, spawn, SETPROP("_SURF_FIND", "_SURF_FIND") }, - { MODKEY, GDK_slash, spawn, SETPROP("_SURF_FIND", "_SURF_FIND") }, + { MODKEY, GDK_g, spawn, SETURI }, + { MODKEY, GDK_f, spawn, SETSEARCH }, + { MODKEY, GDK_slash, spawn, SETSEARCH }, { MODKEY, GDK_n, find, { .b = TRUE } }, { MODKEY|GDK_SHIFT_MASK,GDK_n, find, { .b = FALSE } }, diff --git a/surf.c b/surf.c index 87c10ef..c91db86 100644 --- a/surf.c +++ b/surf.c @@ -319,6 +319,7 @@ cleanup(void) { while(clients) destroyclient(clients); g_free(cookiefile); + g_free(historyfile); g_free(scriptfile); g_free(stylefile); } @@ -772,6 +773,12 @@ loaduri(Client *c, const Arg *arg) { reload(c, &a); } else { webkit_web_view_load_uri(c->view, u); + FILE *f; + if((f = fopen(historyfile, "a+"))) { + fputs(u, f); + fputs("\n", f); + fclose(f); + } c->progress = 0; c->title = copystr(&c->title, u); updatetitle(c); @@ -1222,6 +1229,7 @@ setup(void) { /* dirs and files */ cookiefile = buildpath(cookiefile); + historyfile = buildpath(historyfile); scriptfile = buildpath(scriptfile); cachefolder = buildpath(cachefolder); styledir = buildpath(styledir);
signature.asc
Description: Digital signature