diff -r 32e4e80d659d dmenu.h --- a/dmenu.h Thu Oct 26 12:14:03 2006 +0200 +++ b/dmenu.h Sat Oct 28 12:12:07 2006 +0200 @@ -11,6 +11,9 @@ #define SELBGCOLOR "#666699" #define SELFGCOLOR "#eeeeee" #define SPACE 30 /* px */ + +#define HIST_FILE "/home/robert/.dmenu_history" +#define HIST_SIZE 20 /* color */ enum { ColFG, ColBG, ColLast }; diff -r 32e4e80d659d main.c --- a/main.c Thu Oct 26 12:14:03 2006 +0200 +++ b/main.c Sat Oct 28 12:31:57 2006 +0200 @@ -14,6 +14,7 @@ #include #include + typedef struct Item Item; struct Item { Item *next; /* traverses all items */ @@ -24,6 +25,8 @@ struct Item { /* static */ static char text[4096]; +static char hist[HIST_SIZE][1024]; +static int hcnt = 0; static int mx, my, mw, mh; static int ret = 0; static int nitem = 0; @@ -62,6 +65,45 @@ calcoffsets(void) { if(w > mw) break; } +} + + +static int +writehistory(char *command) { + int i = 0, j = hcnt; + FILE *f; + + if( (f = fopen(HIST_FILE, "w")) ) { + fputs(command, f); + fputc('\n', f); + + for(; istate & ShiftMask) && text) + if((e->state & ShiftMask) && text) fprintf(stdout, "%s", text); - else if(sel) + else if(sel) fprintf(stdout, "%s", sel->text); else if(text) fprintf(stdout, "%s", text); - fflush(stdout); + + (sel == NULL) ? writehistory(text) : writehistory(sel->text); + + + fflush(stdout); running = False; break; case XK_Escape: @@ -236,8 +282,33 @@ readstdin(void) { char *p, buf[1024]; unsigned int len = 0, max = 0; Item *i, *new; + int k; i = 0; + + if( readhistory() ) { + for(k=0; knext = 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') @@ -259,6 +330,7 @@ readstdin(void) { return maxname; } + /* extern */