sites

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 27884338719f6f94a3e7e108cda33fa47136ce5a
parent be8871ab48169a89f4fa72b702744aec5018b6f2
Author: peterjh@trilleee.trilidun.org <unknown>
Date:   Wed, 16 Dec 2009 08:28:25 -0500

Added dmenu-tip-history.diff and description.  Do I need to add this to some
sort of submenu of patches or is it automagic?
Diffstat:
Atools.suckless.org/dmenu/patches/dmenu-tip-history.diff | 145+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Atools.suckless.org/dmenu/patches/history.md | 26++++++++++++++++++++++++++
2 files changed, 171 insertions(+), 0 deletions(-)

diff --git a/tools.suckless.org/dmenu/patches/dmenu-tip-history.diff b/tools.suckless.org/dmenu/patches/dmenu-tip-history.diff @@ -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 +@@ -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 +@@ -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 }; + +@@ -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)) +@@ -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); + } +@@ -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; +@@ -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') +@@ -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 --git a/tools.suckless.org/dmenu/patches/history.md b/tools.suckless.org/dmenu/patches/history.md @@ -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/)> + +