Re: [dev] [surf][patch]history patch update

From: Sébastien Poher <sbphr_AT_volted.net>
Date: Sun, 15 Mar 2015 15:42:07 +0100

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_AT_^ *\\(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



Received on Sun Mar 15 2015 - 15:42:07 CET

This archive was generated by hypermail 2.3.0 : Sun Mar 15 2015 - 15:48:08 CET