From 8d2bb404b561bca1fd7e7a484ac090772337d845 Mon Sep 17 00:00:00 2001 From: Dallin Dahl Date: Fri, 23 Jan 2026 14:04:44 -0700 Subject: [PATCH] load history file on startup for libedit --- edit-edit.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/edit-edit.c b/edit-edit.c index bebea40c..a1e3fd57 100644 --- a/edit-edit.c +++ b/edit-edit.c @@ -19,6 +19,9 @@ void *edit_begin(int fd) { FILE *f; HistEvent he; struct cookie *c; + List *hist; + char line[512]; + FILE *hf; c = ealloc(sizeof *c); if (fd == 0) @@ -33,6 +36,20 @@ void *edit_begin(int fd) { history(c->hist, &he, H_SETSIZE, 20); el_set(c->el, EL_HIST, history, c->hist); + hist = varlookup("history"); + if(hist) { + hf = fopen(hist->w, "r"); + if(!hf) return c; + if(fseek(hf, -5120, SEEK_END) < 0) + rewind(hf); + else + fgets(line, sizeof line, hf); + + while(fgets(line, sizeof line, hf)) + history(c->hist, &he, H_ENTER, line); + fclose(hf); + } + return c; }