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

Re: [PATCH] complete two or more options for zsh



2015/09/23 14:39, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:

> After your change,
> script names are never offered unless you first type at least one
> character that is not "-".

If you type

% zsh <TAB>

then script names (or any file names) *are* offered, but they are
at the end of the long list of options without description (and before
the options with description), so they may be not easy to find.
The real problem is that options are offered even if no '-' is
typed yet. I think this was so even before my patch.

I was using

zstyle ':completion:*' group-name ''

and then the file names were listed before the options (under the
group name 'file').

Anyway, yes, it's better to do all the completion by _arguments alone.
How about the patch below?
(or is it better to create _zsh to do the completion for zsh only?).

> Hm.  Is this a bug in _arguments rather than in the way that _sh
> called _arguments?  That is, should descr ever be a single ":"?


If there is ever an intended effect of specifying '*:' as a helpspec,
then it would better to fix _arguments to do the intended job.

2015/09/20 04:27, I wrote:
> But even with '*:' options without description are listed after
> those with description

This was wrong; I was testing with lots of my own zstyles.
With only 'autoload _Uz compinit; compint', then options with
description are listed after options without description irrespective
of whether I use '*:' or not.

So anyway '*:' seems to have no effect on how the options are ordered.
What is the intended effect of '*:' as a help spec?


diff --git a/Completion/Unix/Command/_sh b/Completion/Unix/Command/_sh
index 1b51122..1b80bd7 100644
--- a/Completion/Unix/Command/_sh
+++ b/Completion/Unix/Command/_sh
@@ -1,12 +1,14 @@
 #compdef sh ksh bash zsh csh tcsh rc
 
 if [[ $service == zsh ]]; then
-  # try a bit harder
-  if [[ ${words[CURRENT-1]} == -o ]]; then
-    _options
-    # no other possibilities
-    return
-  fi
+  _arguments -S -s : \
+    '*-o+[set named option]:option:_options' \
+    '*+o+[unset named option]:option:_options' \
+    '(1 -)-c[run a command]:command:_cmdstring' \
+    '(-)1:script file:_files' \
+    '*:command arguments' \
+    -- && return 0
+  return 1
 fi
 
 if (( CURRENT == ${words[(i)-c]} + 1 )); then
@@ -21,9 +23,3 @@ else
   fi
   _default
 fi
-
-local ret=$?
-
-[[ $service == zsh ]] && _arguments -S -s -- && ret=0
-
-return ret






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