fish-shell/doc_src
Johannes Altmanninger 368017905e builtin commandline: -x for expanded tokens, supplanting -o
Issue #10194 reports Cobra completions do

    set -l args (commandline -opc)
    eval $args[1] __complete $args[2..] (commandline -ct | string escape)

The intent behind "eval" is to expand variables and tildes in "$args".
Fair enough. Several of our own completions do the same, see the next commit.

The problem with "commandline -o" + "eval" is that the former already
removes quotes that are  relevant for "eval". This becomes a problem if $args
contains quoted () or {}, for example this command will wrongly execute a
command substituion:

    git --work-tree='(launch-missiles)' <TAB>

It is possible to escape the string the tokens before running eval, but
then there will be no expansion of variables etc.  The problem is that
"commandline -o" only unescapes tokens so they end up in a weird state
somewhere in-between what the user typed and the expanded version.

Remove the need for "eval" by introducing "commandline -x" which expands
things like variables and braces. This enables custom completion scripts to
be aware of shell variables without eval, see the added test for completions
to "make -C $var/some/dir ".

This means that essentially all third party scripts should migrate from
"commandline -o" to "commandline -x". For example

    set -l tokens
    if commandline -x >/dev/null 2>&1
        set tokens (commandline -xpc)
    else
        set tokens (commandline -opc)
    end

Since this is mainly used for completions, the expansion skips command
substitutions.  They are passed through as-is (instead of cancelling or
expanding to nothing) to make custom completion scripts work reasonably well
in the common case. Of course there are cases where we would want to expand
command substitutions here, so I'm not sure.
2024-01-27 09:28:06 +01:00
..
cmds builtin commandline: -x for expanded tokens, supplanting -o 2024-01-27 09:28:06 +01:00
python_docs_theme doc_src: add print media support to the Sphinx theme 2024-01-12 17:52:43 +01:00
commands.rst docs: Add else and end to keywords list 2024-01-09 16:27:33 +01:00
completions.rst Fix grammar in completion docs 2023-07-09 14:11:01 +08:00
conf.py bump copyright year to 2024 2024-01-06 22:24:55 +08:00
contributing.rst Improve CONTRIBUTING and add it to the docs 2023-06-01 18:09:02 +02:00
design.rst docs: Fix typos 2022-09-17 21:31:06 +08:00
faq.rst docs/faq: Remove external tools 2023-05-25 17:46:25 +02:00
fish_for_bash_users.rst docs: Explain globs more in fish-for-bash-users 2024-01-14 11:06:51 +01:00
fish_indent_lexer.py docs: restore default highlighting keywords and options in HTML 2022-01-16 14:07:19 +01:00
fish_synopsis.py Restyle fishscript and python 2023-06-01 18:20:19 +02:00
index.rst docs: Some slight rewordings 2023-08-23 23:08:56 +02:00
interactive.rst docs: standardise name for vi mode 2023-12-17 17:40:45 +08:00
language.rst docs: Update qmark-noglob status 2024-01-25 18:47:41 +01:00
license.rst Drop unused CMake module CheckIncludeFiles 2024-01-13 22:55:13 +08:00
prompt.rst docs: standardise name for vi mode 2023-12-17 17:40:45 +08:00
relnotes.rst docs: call the CHANGELOG "release notes" 2021-02-25 22:46:24 +08:00
tutorial.rst docs: Some on the tutorial 2023-04-28 17:11:23 +02:00