diff options
author | Jan Moskyto Matejka <mq@ucw.cz> | 2017-05-16 10:35:10 +0200 |
---|---|---|
committer | Jan Moskyto Matejka <mq@ucw.cz> | 2017-05-16 15:34:57 +0200 |
commit | b880e3ffaea12c3231975157bc51b5f90a2f2433 (patch) | |
tree | c207443b43550a8f5cb4e232bd52fa995c39d9ba /client/birdc.c | |
parent | f8d44b01df5d93681e116ccbff39cc4618632825 (diff) |
Bird readline client saves its history.
Diffstat (limited to 'client/birdc.c')
-rw-r--r-- | client/birdc.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/client/birdc.c b/client/birdc.c index 8aa01c17..18e7c47b 100644 --- a/client/birdc.c +++ b/client/birdc.c @@ -29,6 +29,9 @@ static int prompt_active; extern int _rl_vis_botlin; extern void _rl_move_vert(int); +#define HISTORY "/.birdc_history" +static char *history_file; + static void add_history_dedup(char *cmd) { @@ -138,8 +141,23 @@ input_help(int arg, int key UNUSED) } void +history_init(void) +{ + const char *homedir = getenv("HOME"); + if (!homedir) + homedir = "."; + history_file = malloc(strlen(homedir) + sizeof(HISTORY)); + if (!history_file) + die("couldn't alloc enough memory for history file name"); + + sprintf(history_file, "%s%s", homedir, HISTORY); + read_history(history_file); +} + +void input_init(void) { + history_init(); rl_readline_name = "birdc"; rl_add_defun("bird-complete", input_complete, '\t'); rl_add_defun("bird-help", input_help, '?'); @@ -217,5 +235,6 @@ cleanup(void) return; input_hide(); + write_history(history_file); rl_callback_handler_remove(); } |