Commit b880e3ff authored by Jan Moskyto Matejka's avatar Jan Moskyto Matejka

Bird readline client saves its history.

parent f8d44b01
...@@ -29,6 +29,9 @@ static int prompt_active; ...@@ -29,6 +29,9 @@ static int prompt_active;
extern int _rl_vis_botlin; extern int _rl_vis_botlin;
extern void _rl_move_vert(int); extern void _rl_move_vert(int);
#define HISTORY "/.birdc_history"
static char *history_file;
static void static void
add_history_dedup(char *cmd) add_history_dedup(char *cmd)
{ {
...@@ -137,9 +140,24 @@ input_help(int arg, int key UNUSED) ...@@ -137,9 +140,24 @@ input_help(int arg, int key UNUSED)
return 0; return 0;
} }
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 void
input_init(void) input_init(void)
{ {
history_init();
rl_readline_name = "birdc"; rl_readline_name = "birdc";
rl_add_defun("bird-complete", input_complete, '\t'); rl_add_defun("bird-complete", input_complete, '\t');
rl_add_defun("bird-help", input_help, '?'); rl_add_defun("bird-help", input_help, '?');
...@@ -217,5 +235,6 @@ cleanup(void) ...@@ -217,5 +235,6 @@ cleanup(void)
return; return;
input_hide(); input_hide();
write_history(history_file);
rl_callback_handler_remove(); rl_callback_handler_remove();
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment