Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: How about separating "_arguments --" into a new function?



> 2021/10/21 23:15, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:

> The content
> of ${_args_cache_foo} need to be escaped once for their transit through
> lex.c when _foo will be read by compinit, and once against «echo»'s
> treatment of backslashes.

I know.
But if the output of 'cmd --help' already has '\', for example
    --escape     replace $ by \$
then 'print -r' does not work either (if the output of 'print -r' is used
as a spec for _arguments as is).
Using (qq) (instead of (qqq)) may or may not help, but then users must
unset RC_QUOTE (before calling print/echo).
But anyway $_args_cache_cmd is just a 'draft' of _cmd, and users
must edit it manually (usually lots of editing are required).

I'll push the following soon, so feel free to modify/improve it.


diff --git a/Etc/completion-style-guide b/Etc/completion-style-guide
index 62e6a2787..4fa0040a5 100644
--- a/Etc/completion-style-guide
+++ b/Etc/completion-style-guide
@@ -570,3 +570,13 @@ Misc. remarks
       data derived from another command's output to the helper. Consider
       using some variation of the `q` expansion flag to deal with this:
       `_call_program vals $words[1] ${(q-)myfile}'
+10) If you are going to create a new completion function '_cmd' for a
+    command 'cmd', and if the 'cmd' supports the --help option, then you
+    may try
+      compdef _gnu_generic cmd
+      cmd -<TAB>
+    _gnu_generic may not work sufficiently well for 'cmd', but the specs
+    for _arguments generated from the help text are cached in a variable
+    '_args_cache_cmd', and you can save them in a file '_cmd' by
+      print -r -- ${(F)${(@qqq)_args_cache_cmd}} > _cmd
+    and use the file as a draft of the new completion function.










Messages sorted by: Reverse Date, Date, Thread, Author