From 96fca8b4ecfc9fa097a20e7f6396ecbaba21fbf8 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Thu, 27 Jul 2017 21:32:49 -0700 Subject: [PATCH] fix how fish behaves when FISH_HISTORY is set Without this change setting `FISH_HISTORY` causes interactive input to no longer provide autosuggestions, completions, etc. Fixes #4234 --- src/env.cpp | 3 +-- src/reader.cpp | 5 +++++ src/reader.h | 3 +++ 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/env.cpp b/src/env.cpp index 2a4cf434a..eec86d2ec 100644 --- a/src/env.cpp +++ b/src/env.cpp @@ -613,8 +613,7 @@ static void react_to_variable_change(const wcstring &key) { } else if (key == L"FISH_READ_BYTE_LIMIT") { env_set_read_limit(); } else if (key == L"FISH_HISTORY") { - history_destroy(); - reader_push(history_session_id().c_str()); + reader_change_history(history_session_id().c_str()); } } diff --git a/src/reader.cpp b/src/reader.cpp index 8dff6cc6a..c46d13af8 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -1995,6 +1995,11 @@ static parser_test_error_bits_t default_test(const wchar_t *b) { return 0; } +void reader_change_history(const wchar_t *name) { + data->history->save(); + data->history = &history_t::history_with_name(name); +} + void reader_push(const wchar_t *name) { reader_data_t *n = new reader_data_t(); diff --git a/src/reader.h b/src/reader.h index c773ea1ed..3dc0d0802 100644 --- a/src/reader.h +++ b/src/reader.h @@ -72,6 +72,9 @@ const wchar_t *reader_current_filename(); /// \param fn The fileanme to push void reader_push_current_filename(const wchar_t *fn); +/// Change the history file for the current command reading context. +void reader_change_history(const wchar_t *fn); + /// Pop the current filename from the stack of read files. void reader_pop_current_filename();