changeset: 407:a1e9cc79e107
user: peterjh_AT_trilleee.trilidun.org
date: Wed Dec 16 08:28:25 2009 -0500
files: tools.suckless.org/dmenu/patches/dmenu-tip-history.diff tools.suckless.org/dmenu/patches/history.md
description:
Added dmenu-tip-history.diff and description. Do I need to add this to some
sort of submenu of patches or is it automagic?
diff -r 76264082601a -r a1e9cc79e107 tools.suckless.org/dmenu/patches/dmenu-tip-history.diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools.suckless.org/dmenu/patches/dmenu-tip-history.diff Wed Dec 16 08:28:25 2009 -0500
_AT_@ -0,0 +1,145 @@
+diff -r 3c3a635d3de6 dmenu.1
+--- a/dmenu.1 Tue Dec 15 09:52:52 2009 -0500
++++ b/dmenu.1 Tue Dec 15 09:53:41 2009 -0500
+_AT_@ -12,6 +12,7 @@
+ .RB [ \-p " <prompt>"]
+ .RB [ \-sb " <color>"]
+ .RB [ \-sf " <color>"]
++.RB [ \-hist " <filename>"]
+ .RB [ \-v ]
+ .SH DESCRIPTION
+ .SS Overview
+diff -r 3c3a635d3de6 dmenu.c
+--- a/dmenu.c Tue Dec 15 09:52:52 2009 -0500
++++ b/dmenu.c Tue Dec 15 09:53:41 2009 -0500
+_AT_@ -20,6 +20,8 @@
+ #define MIN(a, b) ((a) < (b) ? (a) : (b))
+ #define MAX(a, b) ((a) > (b) ? (a) : (b))
+
++#define HIST_SIZE 20
++
+ /* enums */
+ enum { ColFG, ColBG, ColLast };
+
+_AT_@ -97,6 +99,52 @@
+ static void (*calcoffsets)(void) = calcoffsetsh;
+ static void (*drawmenu)(void) = drawmenuh;
+
++static char hist[HIST_SIZE][1024];
++static char *histfile = NULL;
++static int hcnt = 0;
++
++static int
++writehistory(char *command) {
++ int i = 0, j = hcnt;
++ FILE *f;
++
++ if(!histfile || strlen(command) <= 0)
++ return 0;
++
++ if( (f = fopen(histfile, "w")) ) {
++ fputs(command, f);
++ fputc('\n', f);
++ for(; i<HIST_SIZE && i<j; i++) {
++ if(strcmp(command, hist[i]) != 0) {
++ fputs(hist[i], f);
++ fputc('\n', f);
++ }
++ }
++ fclose(f);
++ return 1;
++ }
++
++ return 0;
++}
++
++static int
++readhistory (void) {
++ char buf[1024];
++ FILE *f;
++
++
++ if(!histfile)
++ return 0;
++
++ if( (f = fopen(histfile, "r+")) ) {
++ while(fgets(buf, sizeof buf, f) && (hcnt < HIST_SIZE))
++ strncpy(hist[hcnt++], buf, (strlen(buf) <= 1024) ? strlen(buf): 1024 );
++ fclose(f);
++ }
++
++ return hcnt;
++}
++
+ void
+ appenditem(Item *i, Item **list, Item **last) {
+ if(!(*last))
+_AT_@ -245,7 +293,7 @@
+ dc.x = mw - spaceitem;
+ dc.w = spaceitem;
+ drawtext(next ? ">" : NULL, dc.norm);
+- }
++ }
+ XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0);
+ XFlush(dpy);
+ }
+_AT_@ -551,6 +599,7 @@
+ fprintf(stdout, "%s", sel->text);
+ else if(*text)
+ fprintf(stdout, "%s", text);
++ writehistory( (sel == NULL) ? text : sel->text);
+ fflush(stdout);
+ running = False;
+ break;
+_AT_@ -628,8 +677,34 @@
+ char *p, buf[1024];
+ unsigned int len = 0, max = 0;
+ Item *i, *new;
++ int k;
++
++ i = 0;
+
+- i = 0;
++ if( readhistory() ) {
++ for(k=0; k<hcnt; k++) {
++ len = strlen(hist[k]);
++ if (hist[k][len - 1] == '\n')
++ hist[k][len - 1] = 0;
++ p = strdup(hist[k]);
++ if(max < len) {
++ maxname = p;
++ max = len;
++ }
++ if(!(new = (Item *)malloc(sizeof(Item))))
++ eprint("fatal: could not malloc() %u bytes\n", sizeof(Item));
++ new->next = new->left = new->right = NULL;
++ new->text = p;
++ if(!i)
++ allitems = new;
++ else
++ i->next = new;
++ i = new;
++ }
++ }
++ len=0; max=0;
++
++
+ while(fgets(buf, sizeof buf, stdin)) {
+ len = strlen(buf);
+ if (buf[len - 1] == '\n')
+_AT_@ -808,11 +883,14 @@
+ else if(!strcmp(argv[i], "-sf")) {
+ if(++i < argc) selfgcolor = argv[i];
+ }
++ else if(!strcmp(argv[i], "-hist")) {
++ if(++i < argc) histfile = argv[i];
++ }
+ else if(!strcmp(argv[i], "-v"))
+ eprint("dmenu-"VERSION", © 2006-2009 dmenu engineers, see LICENSE for details\n");
+ else
+ eprint("usage: dmenu [-i] [-b] [-l <lines>] [-fn <font>] [-nb <color>] [-nf <color>]\n"
+- " [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n");
++ " [-p <prompt>] [-hist <file> ] [-sb <color>] [-sf <color>] [-v]\n");
+ if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
+ fprintf(stderr, "warning: no locale support\n");
+ if(!(dpy = XOpenDisplay(NULL)))
diff -r 76264082601a -r a1e9cc79e107 tools.suckless.org/dmenu/patches/history.md
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tools.suckless.org/dmenu/patches/history.md Wed Dec 16 08:28:25 2009 -0500
_AT_@ -0,0 +1,26 @@
+PASTE
+=====
+
+Description
+-----------
+
+A patch to have dmenu do "smart" history. It will re-order the options in a
+history file based on frequency of use, with the most used heading to the
+top. This is best in conjunct with the history patch to surf. In surf, I
+have "^G" point to:
+
+ dmenu -hist /home/peterjh/.dmenu.history -b -l 10 < ~/.surf/history
+
+Enjoy!
+
+Download
+--------
+
+* [dmenu-tip-history.diff](dmenu-tip-history.diff) (3545) (20091216)
+
+Author
+------
+
+* Peter John Hartman (wart_) <[
http://antiopus.trilidun.org/durandus/](
http://antiopus.trilidun.org/durandus/)>
+
+
changeset: 408:2682be8db32f
tag: tip
user: peterjh_AT_trilleee.trilidun.org
date: Wed Dec 16 08:28:47 2009 -0500
files: surf.suckless.org/patches/surf-tip-history.diff
description:
Oh, and the actual .diff file.
pjh
diff -r a1e9cc79e107 -r 2682be8db32f surf.suckless.org/patches/surf-tip-history.diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/surf.suckless.org/patches/surf-tip-history.diff Wed Dec 16 08:28:47 2009 -0500
_AT_@ -0,0 +1,30 @@
+--- surf.c 2009-10-17 03:00:22.000000000 -0400
++++ surf.c 2009-10-19 15:03:16.000000000 -0400
+_AT_@ -160,6 +160,7 @@ cleanup(void) {
+ while(clients)
+ destroyclient(clients);
+ g_free(cookiefile);
++ g_free(historyfile);
+ g_free(dldir);
+ g_free(scriptfile);
+ g_free(stylefile);
+_AT_@ -420,6 +421,10 @@ loaduri(Client *c, const Arg *arg) {
+ u = g_strrstr(uri, "://") ? g_strdup(uri)
+ : g_strdup_printf("
http://%s", uri);
+ webkit_web_view_load_uri(c->view, u);
++ FILE *f;
++ f = fopen(historyfile, "a+");
++ fprintf(f, u);
++ fclose(f);
+ c->progress = 0;
+ c->title = copystr(&c->title, u);
+ g_free(u);
+_AT_@ -674,6 +679,7 @@ setup(void) {
+
+ /* create dirs and files */
+ cookiefile = buildpath(cookiefile);
++ historyfile = buildpath(historyfile);
+ dldir = buildpath(dldir);
+ scriptfile = buildpath(scriptfile);
+ stylefile =
+buildpath(stylefile);
Received on Wed Dec 16 2009 - 14:29:05 CET