Allow 'commandline' to set the commandline from the prompt

This means that running `commandline foo` will indeed set the text of
the command line to `foo`; it won't get cleared immediately.

Fixes #8807
This commit is contained in:
ridiculousfish 2022-06-04 15:33:55 -07:00
parent cf620c829b
commit 299ed9f903
2 changed files with 23 additions and 4 deletions

View file

@ -2952,9 +2952,12 @@ static int read_i(parser_t &parser) {
while (!check_exit_loop_maybe_warning(data.get())) {
++run_count;
maybe_t<wcstring> tmp = data->readline(0);
if (tmp && !tmp->empty()) {
const wcstring command = tmp.acquire();
if (maybe_t<wcstring> mcmd = data->readline(0)) {
const wcstring command = mcmd.acquire();
if (command.empty()) {
continue;
}
data->update_buff_pos(&data->command_line, 0);
data->command_line.clear();
data->command_line_changed(&data->command_line);
@ -2984,6 +2987,10 @@ static int read_i(parser_t &parser) {
// Reset the warning.
data->did_warn_for_bg_jobs = false;
}
// Apply any command line update from this command or fish_postexec, etc.
// See #8807.
data->apply_commandline_state_changes();
}
}
reader_pop();

View file

@ -2,7 +2,14 @@
from pexpect_helper import SpawnedProc
sp = SpawnedProc()
send, sendline, sleep, expect_prompt, expect_str = sp.send, sp.sendline, sp.sleep, sp.expect_prompt, sp.expect_str
send, sendline, sleep, expect_prompt, expect_re, expect_str = (
sp.send,
sp.sendline,
sp.sleep,
sp.expect_prompt,
sp.expect_re,
sp.expect_str,
)
expect_prompt()
sendline("bind '~' 'handle_tilde'")
@ -47,3 +54,8 @@ sendline("complete -c foo -xa '(commandline)'")
expect_prompt()
send("foo bar \t")
expect_str("foo bar foo\ bar\ ")
send("\b" * 64)
# Commandline works when run on its own (#8807).
sendline("commandline whatever")
expect_re("prompt [0-9]+>whatever")