diff --git a/src/env_dispatch.cpp b/src/env_dispatch.cpp index 4181c7e1a..4323ea5b7 100644 --- a/src/env_dispatch.cpp +++ b/src/env_dispatch.cpp @@ -235,6 +235,14 @@ static void handle_fish_history_change(const env_stack_t &vars) { reader_change_history(history_session_id(vars)); } +static void handle_autosuggestion_change(const env_stack_t &vars) { + bool enabled = true; + if (auto val = vars.get(L"fish_autosuggestion_enabled")) { + if (val->as_string() == L"0") enabled = false; + } + reader_set_autosuggestion_enabled(enabled); +} + static void handle_function_path_change(const env_stack_t &vars) { UNUSED(vars); function_invalidate_path(); @@ -340,6 +348,7 @@ static std::unique_ptr create_dispatch_table() { var_dispatch_table->add(L"fish_function_path", handle_function_path_change); var_dispatch_table->add(L"fish_read_limit", handle_read_limit_change); var_dispatch_table->add(L"fish_history", handle_fish_history_change); + var_dispatch_table->add(L"fish_autosuggestion_enabled", handle_autosuggestion_change); var_dispatch_table->add(L"TZ", handle_tz_change); var_dispatch_table->add(L"fish_use_posix_spawn", handle_fish_use_posix_spawn_change); var_dispatch_table->add(L"fish_trace", handle_fish_trace); diff --git a/src/reader.cpp b/src/reader.cpp index be0d561eb..c1014cfc0 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -603,7 +603,7 @@ struct layout_data_t { class reader_data_t : public std::enable_shared_from_this { public: /// Configuration for the reader. - const reader_config_t conf; + reader_config_t conf; /// The parser being used. std::shared_ptr parser_ref; /// String containing the whole current commandline. @@ -2612,6 +2612,18 @@ void reader_change_history(const wcstring &name) { } } +void reader_set_autosuggestion_enabled(bool enable) { + // We don't need to _change_ if we're not initialized yet. + reader_data_t *data = current_data_or_null(); + if (data) { + if (data->conf.autosuggest_ok != enable) { + data->conf.autosuggest_ok = enable; + data->force_exec_prompt_and_repaint = true; + data->inputter.queue_char(readline_cmd_t::repaint); + } + } +} + /// Add a new reader to the reader stack. /// \return a shared pointer to it. static std::shared_ptr reader_push_ret(parser_t &parser, diff --git a/src/reader.h b/src/reader.h index 911510847..31dad3b97 100644 --- a/src/reader.h +++ b/src/reader.h @@ -149,6 +149,9 @@ void restore_term_mode(); /// Change the history file for the current command reading context. void reader_change_history(const wcstring &name); +/// Enable or disable autosuggestions. +void reader_set_autosuggestion_enabled(bool enable); + /// Write the title to the titlebar. This function is called just before a new application starts /// executing and just after it finishes. ///