From ce371e188141f56868843c0d08d2cd7db9e8cd75 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Wed, 21 Jul 2021 15:35:22 -0700 Subject: [PATCH] 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 a32248277f02. --- src/builtin_commandline.cpp | 6 +++++- tests/pexpects/commandline.py | 5 +++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/builtin_commandline.cpp b/src/builtin_commandline.cpp index dff824e31..512a10c2e 100644 --- a/src/builtin_commandline.cpp +++ b/src/builtin_commandline.cpp @@ -212,6 +212,7 @@ maybe_t 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 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(); diff --git a/tests/pexpects/commandline.py b/tests/pexpects/commandline.py index 321013c23..02941b30f 100644 --- a/tests/pexpects/commandline.py +++ b/tests/pexpects/commandline.py @@ -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")