fish-shell/doc_src/cmds
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
..
_.rst docs synopsis: add HTML highlighing and automate manpage markup 2022-01-19 22:56:41 +08:00
abbr.rst docs/abbr: Explain saving abbrs 2023-07-04 18:30:28 +02:00
alias.rst docs: Remove the term "wrapper" 2022-12-21 16:24:00 +01:00
and.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
argparse.rst docs: Add argparse examples on how to use the flags 2024-01-14 10:20:11 +01:00
begin.rst docs: omnibus cleanup 2022-03-12 00:21:13 +08:00
bg.rst docs: Improve bg docs 2023-06-05 18:26:13 +02:00
bind.rst docs: standardise name for vi mode 2023-12-17 17:40:45 +08:00
block.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
break.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
breakpoint.rst docs synopsis: add HTML highlighing and automate manpage markup 2022-01-19 22:56:41 +08:00
builtin.rst docs: Document type/builtin exit status 2022-09-30 18:50:14 +02:00
case.rst docs synopsis: add HTML highlighing and automate manpage markup 2022-01-19 22:56:41 +08:00
cd.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
cdh.rst docs: Add some more envvars to reference 2022-12-01 18:00:06 +01:00
command.rst docs/command: Simplify 2024-01-22 21:44:59 +01:00
commandline.rst builtin commandline: -x for expanded tokens, supplanting -o 2024-01-27 09:28:06 +01:00
complete.rst docs/complete: List --description with the options 2023-11-14 16:32:43 +01:00
contains.rst docs: omnibus cleanup 2022-03-12 00:21:13 +08:00
continue.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
count.rst docs synopsis: make all placeholder arguments uppercase 2022-01-19 22:56:41 +08:00
dirh.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
dirs.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
disown.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
echo.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
else.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
emit.rst docs: omnibus cleanup 2022-03-12 00:21:13 +08:00
end.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
eval.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
exec.rst docs: omnibus cleanup 2022-03-12 00:21:13 +08:00
exit.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
false.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
fg.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
fish_add_path.rst docs/fish_add_path: Also clarify the examples 2023-04-04 17:55:10 +02:00
fish_breakpoint_prompt.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
fish_clipboard_copy.rst Document fish_clipboard_copy/paste 2022-10-19 20:10:26 +02:00
fish_clipboard_paste.rst Document fish_clipboard_copy/paste 2022-10-19 20:10:26 +02:00
fish_command_not_found.rst docs synopsis: add HTML highlighing and automate manpage markup 2022-01-19 22:56:41 +08:00
fish_config.rst docs: Turn off highlighting correctly in fish_config 2023-06-16 16:17:58 +02:00
fish_default_key_bindings.rst Create fish_[default|vi]_key_bindings documentation 2023-04-19 19:22:55 +02:00
fish_delta.rst Add a fish_delta helper function 2022-10-19 20:06:35 +02:00
fish_git_prompt.rst git prompt: Interpret values of "1", "yes" or "true" as true for bools instead of relying on defined-or-not (#9274) 2022-10-21 20:22:20 +02:00
fish_greeting.rst docs: fix double space in example fish_greeting 2024-01-06 15:26:20 +01:00
fish_hg_prompt.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
fish_indent.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
fish_is_root_user.rst docs synopsis: add HTML highlighing and automate manpage markup 2022-01-19 22:56:41 +08:00
fish_key_reader.rst fish_key_reader: Humanize key descriptions 2023-08-26 10:43:42 +02:00
fish_mode_prompt.rst docs: standardise name for vi mode 2023-12-17 17:40:45 +08:00
fish_opt.rst Fix small typos 2023-11-18 18:27:25 -08:00
fish_prompt.rst docs synopsis: add HTML highlighing and automate manpage markup 2022-01-19 22:56:41 +08:00
fish_right_prompt.rst We no longer have two doc systems, move sphinx_doc_src back to doc_src 2020-02-19 17:00:35 -08:00
fish_status_to_signal.rst docs synopsis: add HTML highlighing and automate manpage markup 2022-01-19 22:56:41 +08:00
fish_svn_prompt.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
fish_title.rst docs synopsis: add HTML highlighing and automate manpage markup 2022-01-19 22:56:41 +08:00
fish_update_completions.rst docs synopsis: add HTML highlighing and automate manpage markup 2022-01-19 22:56:41 +08:00
fish_vcs_prompt.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
fish_vi_key_bindings.rst docs: standardise name for vi mode 2023-12-17 17:40:45 +08:00
fish.rst docs synopsis: add HTML highlighing and automate manpage markup 2022-01-19 22:56:41 +08:00
for.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
funced.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
funcsave.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
function.rst docs: Call it "reserved words" 2024-01-14 10:40:51 +01:00
functions.rst functions --copy: store file and lineno (#9542) 2023-02-13 09:59:28 -06:00
help.rst docs: More about envvars 2023-01-09 20:33:37 +01:00
history.rst history: Allow deleting ranges 2023-06-10 15:35:40 +02:00
if.rst docs/if: Link to other builtins 2023-02-28 20:49:11 +01:00
isatty.rst Fix formatting for isatty 2022-10-19 20:10:26 +02:00
jobs.rst docs: Fix typos 2022-09-17 21:31:06 +08:00
math.rst math: Fix docs on --scale 2023-08-25 16:17:59 +02:00
nextd.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
not.rst docs: omnibus cleanup 2022-03-12 00:21:13 +08:00
open.rst docs synopsis: add HTML highlighing and automate manpage markup 2022-01-19 22:56:41 +08:00
or.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
path.rst docs/path: Remove incorrect status comments 2023-08-24 18:06:03 +02:00
popd.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
prevd.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
printf.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
prompt_hostname.rst docs synopsis: add HTML highlighing and automate manpage markup 2022-01-19 22:56:41 +08:00
prompt_login.rst docs: omnibus cleanup 2022-03-12 00:21:13 +08:00
prompt_pwd.rst docs/prompt_pwd: Fix envvar linking 2022-12-30 14:31:32 +01:00
psub.rst docs: omnibus cleanup 2022-03-12 00:21:13 +08:00
pushd.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
pwd.rst docs: omnibus cleanup 2022-03-12 00:21:13 +08:00
random.rst docs: omnibus cleanup 2022-03-12 00:21:13 +08:00
read.rst docs/read: Specify default scope 2023-10-19 21:12:54 +02:00
realpath.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
return.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
set_color.rst docs: Fix markdown links 2023-11-22 18:42:34 +01:00
set.rst docs/set: Fix typo 2024-01-02 21:54:07 +01:00
source.rst docs: omnibus cleanup 2022-03-12 00:21:13 +08:00
status.rst Add status current-commandline 2022-10-26 12:15:02 -05:00
string-collect.rst Fix more lost string documentation 2022-05-14 10:05:02 +02:00
string-escape.rst string docs: format options and arguments in line with other pages 2022-03-12 22:22:02 +08:00
string-join.rst New -n flag for string join. (#8774) 2022-03-13 11:47:33 +01:00
string-join0.rst We no longer have two doc systems, move sphinx_doc_src back to doc_src 2020-02-19 17:00:35 -08:00
string-length.rst string docs: format options and arguments in line with other pages 2022-03-12 22:22:02 +08:00
string-lower.rst string docs: format options and arguments in line with other pages 2022-03-12 22:22:02 +08:00
string-match.rst docs/string: Add a -- example to the match section 2023-01-08 12:44:02 +01:00
string-pad.rst docs/string: Separate "pad" and "shorten" 2023-04-20 22:17:08 +02:00
string-repeat.rst string docs: format options and arguments in line with other pages 2022-03-12 22:22:02 +08:00
string-replace.rst string docs: format options and arguments in line with other pages 2022-03-12 22:22:02 +08:00
string-shorten.rst docs/string: Separate "pad" and "shorten" 2023-04-20 22:17:08 +02:00
string-split.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
string-split0.rst We no longer have two doc systems, move sphinx_doc_src back to doc_src 2020-02-19 17:00:35 -08:00
string-sub.rst Fix more lost string documentation 2022-05-14 10:05:02 +02:00
string-trim.rst string docs: format options and arguments in line with other pages 2022-03-12 22:22:02 +08:00
string-unescape.rst We no longer have two doc systems, move sphinx_doc_src back to doc_src 2020-02-19 17:00:35 -08:00
string-upper.rst string docs: format options and arguments in line with other pages 2022-03-12 22:22:02 +08:00
string.rst docs/string: Separate "pad" and "shorten" 2023-04-20 22:17:08 +02:00
suspend.rst docs: omnibus cleanup 2022-03-12 00:21:13 +08:00
switch.rst docs: More about envvars 2023-01-09 20:33:37 +01:00
test.rst docs: Clarify a sentence in the test docs 2023-08-20 22:10:30 +02:00
time.rst docs: Explain what times output means 2022-12-01 17:56:57 +01:00
trap.rst Allow trapping SIGINT and SIGTERM in scripts 2022-05-28 17:44:13 -07:00
true.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00
type.rst docs/type: Correct "--no-functions" 2023-08-21 17:44:21 +02:00
ulimit.rst docs: Fix typos 2022-09-17 21:31:06 +08:00
umask.rst docs: standardise on definition lists for options 2022-03-12 00:21:12 +08:00
vared.rst docs: omnibus cleanup 2022-03-12 00:21:13 +08:00
wait.rst docs: omnibus cleanup 2022-03-12 00:21:13 +08:00
while.rst docs: Use :doc: role when linking to commands 2022-09-24 10:56:43 +02:00