Read $fish_autosuggestion_enabled on interactive startup

This allows to disable autosuggestions in config or with

	fish -C 'set -g fish_autosuggestion_enabled 0'

instead of only in existing interactive sessions.

I'm not sure if passing the env var table is actually necessary here,
since we already have a reader.
This commit is contained in:
Johannes Altmanninger 2021-11-14 11:08:30 +01:00
parent 0f1bc5335a
commit a32fa8fac9
3 changed files with 14 additions and 10 deletions

View file

@ -247,12 +247,8 @@ 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);
void handle_autosuggestion_change(const env_stack_t &vars) {
reader_set_autosuggestion_enabled(vars);
}
static void handle_function_path_change(const env_stack_t &vars) {

View file

@ -2612,10 +2612,18 @@ void reader_change_history(const wcstring &name) {
}
}
void reader_set_autosuggestion_enabled(bool enable) {
static bool check_autosuggestion_enabled(const env_stack_t &vars) {
if (auto val = vars.get(L"fish_autosuggestion_enabled")) {
return val->as_string() != L"0";
}
return true;
}
void reader_set_autosuggestion_enabled(const env_stack_t &vars) {
// We don't need to _change_ if we're not initialized yet.
reader_data_t *data = current_data_or_null();
if (data) {
bool enable = check_autosuggestion_enabled(vars);
if (data->conf.autosuggest_ok != enable) {
data->conf.autosuggest_ok = enable;
data->force_exec_prompt_and_repaint = true;
@ -2768,7 +2776,7 @@ static int read_i(parser_t &parser) {
conf.complete_ok = true;
conf.highlight_ok = true;
conf.syntax_check_ok = true;
conf.autosuggest_ok = true;
conf.autosuggest_ok = check_autosuggestion_enabled(parser.vars());
conf.expand_abbrev_ok = true;
if (parser.is_breakpoint() && function_exists(DEBUG_PROMPT_FUNCTION_NAME, parser)) {

View file

@ -149,8 +149,8 @@ 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);
/// Enable or disable autosuggestions based on the associated variable.
void reader_set_autosuggestion_enabled(const env_stack_t &vars);
/// Write the title to the titlebar. This function is called just before a new application starts
/// executing and just after it finishes.