Put back support for undocumented -I option to commandline

This allows operating on a user-specified commandline instead of the
true contents. This was inadvertently removed in a32248277f.
This commit is contained in:
ridiculousfish 2021-07-21 15:35:22 -07:00
parent 0f127cc7f3
commit ce371e1881
2 changed files with 10 additions and 1 deletions

View file

@ -212,6 +212,7 @@ maybe_t<int> builtin_commandline(parser_t &parser, io_streams_t &streams, const
break;
}
case 'I': {
// A historical, undocumented feature. TODO: consider removing this.
override_buffer = w.woptarg;
break;
}
@ -366,7 +367,10 @@ maybe_t<int> builtin_commandline(parser_t &parser, io_streams_t &streams, const
const wchar_t *current_buffer = nullptr;
size_t current_cursor_pos{0};
wcstring transient;
if (!ld.transient_commandlines.empty() && !cursor_mode) {
if (override_buffer) {
current_buffer = override_buffer;
current_cursor_pos = std::wcslen(current_buffer);
} else if (!ld.transient_commandlines.empty() && !cursor_mode) {
transient = ld.transient_commandlines.back();
current_buffer = transient.c_str();
current_cursor_pos = transient.size();

View file

@ -36,3 +36,8 @@ sendline("set what (commandline)")
expect_prompt()
sendline('echo "<$what>"')
expect_prompt("<>")
# Test for undocumented -I flag.
# TODO: consider removing.
sendline("commandline -I foo")
expect_prompt("foo")