Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [PATCH] complete two or more options for zsh
On 2015/10/01, at 1:19, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
> Probably the ideal way to complete script args is to use "compset -n"
> to simulate the script name appearing in command position, and then
> call _normal.
Before sending the previous patch I tried
*::script argumets:_normal
and the following worked (IF script had its own compdef):
% zsh script <TAB> # or -<TAB>
But then I thought there would be not much chance that the user had
defined compdef for the script; otherwise it would just complete files.
(Or are there any difference even if there is no compdef for the script?)
And it caused 'zsh -s <TAB>' to complete executables instead of arguments.
So I thought it would just be enough to call _files.
But, yes, maybe calling _normal would be useful for some users.
How about the following? (includes my previous patch)
diff --git a/Completion/Unix/Command/_zsh b/Completion/Unix/Command/_zsh
index 3b6d7ad..a541467 100644
--- a/Completion/Unix/Command/_zsh
+++ b/Completion/Unix/Command/_zsh
@@ -1,8 +1,23 @@
#compdef zsh
+local curcontext=$curcontext state state_descr line expl
+typeset -A opt_args
+
_arguments -S -s : \
'*-o+[set named option]:option:_options' \
'*+o+[unset named option]:option:_options' \
+ '(1 -s --shinstdin)'{-s,--shinstdin}'[read commands from standard input]' \
+ '(-)-b[end of option processing, like --]' \
'(1 -)-c[run a command]:command:_cmdstring' \
'(-)1:script file:_files' \
- '*:command arguments' --
+ '*::script arguments:->args' -- && return 0
+
+case $state in
+ (args)
+ if [[ -n ${opt_args[(I)-c|-s|--shinstdin]} ]]; then
+ _files
+ else
+ _normal
+ fi
+ ;;
+esac
Messages sorted by:
Reverse Date,
Date,
Thread,
Author