From 2611646232ee4ab11018147b20413a9959abcba1 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Thu, 18 Dec 2025 09:29:55 +0100 Subject: [PATCH] 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 --- CHANGELOG.rst | 1 + po/de.po | 4 ++++ po/en.po | 4 ++++ po/fr.po | 4 ++++ po/pl.po | 4 ++++ po/pt_BR.po | 4 ++++ po/sv.po | 4 ++++ po/zh_CN.po | 4 ++++ po/zh_TW.po | 4 ++++ src/builtins/commandline.rs | 13 ++++++++++--- tests/checks/complete.fish | 5 +++++ 11 files changed, 48 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 9fa47731f..c005fe149 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -32,6 +32,7 @@ Deprecations and removed features Scripting improvements ---------------------- - New :ref:`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 ------------------------ diff --git a/po/de.po b/po/de.po index 7d5cb0966..d78472b34 100644 --- a/po/de.po +++ b/po/de.po @@ -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" diff --git a/po/en.po b/po/en.po index 866e66bfb..2ec027be2 100644 --- a/po/en.po +++ b/po/en.po @@ -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 "" diff --git a/po/fr.po b/po/fr.po index 0eec8f7e6..6d4b8c0cb 100644 --- a/po/fr.po +++ b/po/fr.po @@ -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 "" diff --git a/po/pl.po b/po/pl.po index a5e8dde40..101ec79dc 100644 --- a/po/pl.po +++ b/po/pl.po @@ -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 "" diff --git a/po/pt_BR.po b/po/pt_BR.po index d14a3d6a6..130307461 100644 --- a/po/pt_BR.po +++ b/po/pt_BR.po @@ -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 "" diff --git a/po/sv.po b/po/sv.po index b207e0782..7ba8c0dae 100644 --- a/po/sv.po +++ b/po/sv.po @@ -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 "" diff --git a/po/zh_CN.po b/po/zh_CN.po index 72ed246d3..35726000e 100644 --- a/po/zh_CN.po +++ b/po/zh_CN.po @@ -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" diff --git a/po/zh_TW.po b/po/zh_TW.po index 9004b15bd..29d28774c 100644 --- a/po/zh_TW.po +++ b/po/zh_TW.po @@ -761,6 +761,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" diff --git a/src/builtins/commandline.rs b/src/builtins/commandline.rs index 7d89e9d25..07c949d8e 100644 --- a/src/builtins/commandline.rs +++ b/src/builtins/commandline.rs @@ -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(); diff --git a/tests/checks/complete.fish b/tests/checks/complete.fish index 0d34aa9bb..d797a02f0 100644 --- a/tests/checks/complete.fish +++ b/tests/checks/complete.fish @@ -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