From 7e7355bde1a6b1aa3a8ef6817eddd20a5f8ffc62 Mon Sep 17 00:00:00 2001 From: Fabian Homborg Date: Sat, 19 Dec 2020 11:37:01 +0100 Subject: [PATCH] Restore $status after expanding completions When a completion's "--arguments" script ran, it would clobber $status with its value, so when you repainted your prompt, it would now show the completion script's status rather than the status of what you last ran. Solve this by just storing the status and restoring it - other places do this by calling exec_subshell with apply_exit_status set to false, which does basically the same thing. We can't use it here because we don't want to run a "full" script, we only want the arguments to be expanded, without a "real" command. No, I have no idea how to test this automatically. Fixes #7555. --- src/complete.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/complete.cpp b/src/complete.cpp index 4ce2c7fe2..06e682e05 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -808,9 +808,11 @@ void completer_t::complete_from_args(const wcstring &str, const wcstring &args, bool is_autosuggest = (this->type() == COMPLETE_AUTOSUGGEST); bool saved_interactive = false; + statuses_t status; if (ctx.parser) { saved_interactive = ctx.parser->libdata().is_interactive; ctx.parser->libdata().is_interactive = false; + status = ctx.parser->get_last_statuses(); } expand_flags_t eflags{}; @@ -822,6 +824,7 @@ void completer_t::complete_from_args(const wcstring &str, const wcstring &args, if (ctx.parser) { ctx.parser->libdata().is_interactive = saved_interactive; + ctx.parser->set_last_statuses(status); } this->complete_strings(escape_string(str, ESCAPE_ALL), const_desc(desc), possible_comp, flags);