diff --git a/src/complete.cpp b/src/complete.cpp index 7de4638ae..feafd1822 100644 --- a/src/complete.cpp +++ b/src/complete.cpp @@ -1336,10 +1336,13 @@ void completer_t::complete_custom(const wcstring &cmd, const wcstring &cmdline, // Perhaps set a transient commandline so that custom completions // buitin_commandline will refer to the wrapped command. But not if // we're doing autosuggestions. + maybe_t remove_transient{}; bool wants_transient = depth > 0 && !is_autosuggest; if (wants_transient) { ctx.parser->libdata().transient_commandlines.push_back(cmdline); + remove_transient.emplace([&] { ctx.parser->libdata().transient_commandlines.pop_back(); }); } + maybe_t equals_pos = variable_assignment_equals_pos(cmd); bool is_variable_assignment = bool(equals_pos); if (is_variable_assignment && !is_autosuggest) { @@ -1385,9 +1388,6 @@ void completer_t::complete_custom(const wcstring &cmd, const wcstring &cmdline, !had_ddash)) { // Invoke any custom completions for this command. *do_file = false; } - if (wants_transient) { - ctx.parser->libdata().transient_commandlines.pop_back(); - } } // Given a command line \p command_line and the range of the command itself within the