commandline --cursor: respect transient command line

We have logic to prevent "commandline --cursor 123" inside "complete
-C" from setting the transient commandline's cursor.

But reading this cursor ("commandline --cursor")
is fine and expected to work by completion scripts.

I don't expect there is a use case for setting the cursor while
computing completions, so let's make that an error for now.
Could revisit that.

Closes #11993
This commit is contained in:
Johannes Altmanninger
2025-12-18 09:29:55 +01:00
parent 08600d012f
commit 2611646232
11 changed files with 48 additions and 3 deletions

View File

@@ -32,6 +32,7 @@ Deprecations and removed features
Scripting improvements
----------------------
- New :ref:`status language <status-language>` commands allow showing and modifying language settings for fish messages without having to modify environment variables.
- When using a noninteractive fish instance to compute completions, ``commandline --cursor`` no works as expected instead of throwing an error (:issue:`11993`).
Interactive improvements
------------------------

View File

@@ -767,6 +767,10 @@ msgstr "%s: realpath fehlgeschlagen: %s\n"
msgid "%s: scope can be only one of: universal function global local\n"
msgstr ""
#, c-format
msgid "%s: setting cursor while evaluating 'complete --arguments' is not yet supported"
msgstr ""
#, c-format
msgid "%s: stdin is closed\n"
msgstr "%s: stdin ist geschlossen\n"

View File

@@ -765,6 +765,10 @@ msgstr ""
msgid "%s: scope can be only one of: universal function global local\n"
msgstr ""
#, c-format
msgid "%s: setting cursor while evaluating 'complete --arguments' is not yet supported"
msgstr ""
#, c-format
msgid "%s: stdin is closed\n"
msgstr ""

View File

@@ -896,6 +896,10 @@ msgstr ""
msgid "%s: scope can be only one of: universal function global local\n"
msgstr ""
#, c-format
msgid "%s: setting cursor while evaluating 'complete --arguments' is not yet supported"
msgstr ""
#, c-format
msgid "%s: stdin is closed\n"
msgstr ""

View File

@@ -761,6 +761,10 @@ msgstr ""
msgid "%s: scope can be only one of: universal function global local\n"
msgstr ""
#, c-format
msgid "%s: setting cursor while evaluating 'complete --arguments' is not yet supported"
msgstr ""
#, c-format
msgid "%s: stdin is closed\n"
msgstr ""

View File

@@ -766,6 +766,10 @@ msgstr ""
msgid "%s: scope can be only one of: universal function global local\n"
msgstr ""
#, c-format
msgid "%s: setting cursor while evaluating 'complete --arguments' is not yet supported"
msgstr ""
#, c-format
msgid "%s: stdin is closed\n"
msgstr ""

View File

@@ -762,6 +762,10 @@ msgstr ""
msgid "%s: scope can be only one of: universal function global local\n"
msgstr ""
#, c-format
msgid "%s: setting cursor while evaluating 'complete --arguments' is not yet supported"
msgstr ""
#, c-format
msgid "%s: stdin is closed\n"
msgstr ""

View File

@@ -788,6 +788,10 @@ msgstr "%s: realpath 失败:%s\n"
msgid "%s: scope can be only one of: universal function global local\n"
msgstr "%s: 范围只能是universal通用function函数global全局local局域\n"
#, c-format
msgid "%s: setting cursor while evaluating 'complete --arguments' is not yet supported"
msgstr ""
#, c-format
msgid "%s: stdin is closed\n"
msgstr "%s: stdin 已关闭\n"

View File

@@ -761,6 +761,10 @@ msgstr "%srealpath 失敗:%s\n"
msgid "%s: scope can be only one of: universal function global local\n"
msgstr "%s作用域只能是以下之一universal、function、global、local\n"
#, c-format
msgid "%s: setting cursor while evaluating 'complete --arguments' is not yet supported"
msgstr ""
#, c-format
msgid "%s: stdin is closed\n"
msgstr "%sstdin 已關閉\n"

View File

@@ -616,8 +616,7 @@ pub fn commandline(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr])
// At this point we have (nearly) exhausted the options which always operate on the true command
// line. Now we respect the possibility of a transient command line due to evaluating a wrapped
// completion. Don't do this in cursor_mode: it makes no sense to move the cursor based on a
// transient commandline.
// completion.
let current_buffer;
let current_cursor_pos;
let transient;
@@ -632,7 +631,15 @@ pub fn commandline(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr])
} else if let Some(override_buffer) = &override_buffer {
current_buffer = override_buffer;
current_cursor_pos = current_buffer.len();
} else if parser.libdata().transient_commandline.is_some() && !cursor_mode {
} else if parser.libdata().transient_commandline.is_some() {
if cursor_mode && positional_args != 0 {
streams.err.append(wgettext_fmt!(
"%s: setting cursor while evaluating 'complete --arguments' is not yet supported",
cmd
));
builtin_print_error_trailer(parser, streams.err, cmd);
return Err(STATUS_CMD_ERROR);
}
transient = parser.libdata().transient_commandline.clone().unwrap();
current_buffer = &transient;
current_cursor_pos = transient.len();

View File

@@ -686,3 +686,8 @@ complete somewrapper3
# CHECK: complete somewrapper3
# CHECK: complete somewrapper3
# CHECK: complete somewrapper3 --wraps wrapped1
complete command-line-aware-completions -xa "(commandline --cursor; commandline --current-process)"
complete -C"command-line-aware-completions "
# CHECK: 31
# CHECK: command-line-aware-completions