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

From: Markus Teich <markus.teich_AT_stusta.mhn.de>
Date: Sun, 15 Mar 2015 13:12:19 +0100

Heyho S├ębastien,

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);
}

> 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.

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.

--Markus
Received on Sun Mar 15 2015 - 13:12:19 CET

This archive was generated by hypermail 2.3.0 : Sun Mar 15 2015 - 13:24:04 CET