diff --git a/src/expand.cpp b/src/expand.cpp index 5bcd896e7..591d8e94f 100644 --- a/src/expand.cpp +++ b/src/expand.cpp @@ -328,9 +328,10 @@ static bool expand_variables(const wcstring &instr, std::vector *o history_t *history = nullptr; maybe_t var{}; if (var_name == L"history") { - // We do this only on the main thread, matching env.cpp. + // Note reader_get_history may return null, if we are running non-interactively (e.g. from + // web_config). if (is_main_thread()) { - history = reader_get_history(); + history = &history_t::history_with_name(history_session_id()); } } else if (var_name != wcstring{VARIABLE_EXPAND_EMPTY}) { var = env_get(var_name); diff --git a/src/reader.cpp b/src/reader.cpp index e8d013f3d..188d7b40e 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -2026,7 +2026,7 @@ static parser_test_error_bits_t default_test(const wcstring &b) { return 0; } -void reader_change_history(const wchar_t *name) { +void reader_change_history(const wcstring &name) { // We don't need to _change_ if we're not initialized yet. reader_data_t *data = current_data_or_null(); if (data && data->history) { diff --git a/src/reader.h b/src/reader.h index cf5f2029d..1de190852 100644 --- a/src/reader.h +++ b/src/reader.h @@ -70,7 +70,7 @@ const wchar_t *reader_current_filename(); 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); +void reader_change_history(const wcstring &name); /// Pop the current filename from the stack of read files. void reader_pop_current_filename();