mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-31 23:28:45 +00:00
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:
parent
0f1bc5335a
commit
a32fa8fac9
3 changed files with 14 additions and 10 deletions
|
@ -247,12 +247,8 @@ static void handle_fish_history_change(const env_stack_t &vars) {
|
||||||
reader_change_history(history_session_id(vars));
|
reader_change_history(history_session_id(vars));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void handle_autosuggestion_change(const env_stack_t &vars) {
|
void handle_autosuggestion_change(const env_stack_t &vars) {
|
||||||
bool enabled = true;
|
reader_set_autosuggestion_enabled(vars);
|
||||||
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) {
|
static void handle_function_path_change(const env_stack_t &vars) {
|
||||||
|
|
|
@ -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.
|
// We don't need to _change_ if we're not initialized yet.
|
||||||
reader_data_t *data = current_data_or_null();
|
reader_data_t *data = current_data_or_null();
|
||||||
if (data) {
|
if (data) {
|
||||||
|
bool enable = check_autosuggestion_enabled(vars);
|
||||||
if (data->conf.autosuggest_ok != enable) {
|
if (data->conf.autosuggest_ok != enable) {
|
||||||
data->conf.autosuggest_ok = enable;
|
data->conf.autosuggest_ok = enable;
|
||||||
data->force_exec_prompt_and_repaint = true;
|
data->force_exec_prompt_and_repaint = true;
|
||||||
|
@ -2768,7 +2776,7 @@ static int read_i(parser_t &parser) {
|
||||||
conf.complete_ok = true;
|
conf.complete_ok = true;
|
||||||
conf.highlight_ok = true;
|
conf.highlight_ok = true;
|
||||||
conf.syntax_check_ok = true;
|
conf.syntax_check_ok = true;
|
||||||
conf.autosuggest_ok = true;
|
conf.autosuggest_ok = check_autosuggestion_enabled(parser.vars());
|
||||||
conf.expand_abbrev_ok = true;
|
conf.expand_abbrev_ok = true;
|
||||||
|
|
||||||
if (parser.is_breakpoint() && function_exists(DEBUG_PROMPT_FUNCTION_NAME, parser)) {
|
if (parser.is_breakpoint() && function_exists(DEBUG_PROMPT_FUNCTION_NAME, parser)) {
|
||||||
|
|
|
@ -149,8 +149,8 @@ void restore_term_mode();
|
||||||
/// Change the history file for the current command reading context.
|
/// Change the history file for the current command reading context.
|
||||||
void reader_change_history(const wcstring &name);
|
void reader_change_history(const wcstring &name);
|
||||||
|
|
||||||
/// Enable or disable autosuggestions.
|
/// Enable or disable autosuggestions based on the associated variable.
|
||||||
void reader_set_autosuggestion_enabled(bool enable);
|
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
|
/// Write the title to the titlebar. This function is called just before a new application starts
|
||||||
/// executing and just after it finishes.
|
/// executing and just after it finishes.
|
||||||
|
|
Loading…
Reference in a new issue