Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH: Improve _zargs
- X-seq: zsh-workers 35673
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH: Improve _zargs
- Date: Fri, 3 Jul 2015 14:14:29 +0200
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:subject:date:message-id; bh=dBRTHe2j+4BW5M55fZL8Yk/f0WFawksnZRnvKfIl7do=; b=ywM5r0VyDjT9+Rw/+0lFPs/prWSaPCUG0AQM81CrijBG3PCisBctSSWUEZJLMlO2Wp BWrtZZfTuvPPpk8FawXIKWjTVNFHppSbRqFVqWOkYbTeyog+foV9XTg8M/JAZ6IeEbS5 rNbpeWwkARe2CsX6Dz1m34kk4G9sGcvbshW1rjOjAG7KwOoQsnOWY2Tuf86UcLgSx0/W +KLL+HFakyerzK2Ne4H1ghs9ZCqAPi2qdQP2nlLiH0iUhIVuYyCQZ+KmsJUjFh9WU1oD GfRdfUUk235ignbzHcIO7CeD3VnBZf7P8RK3eZaPQ7i8V5NLRM+BWeGw6Tgx+PNWPYbt U1HA==
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
I noticed the zargs completion didn't do much, this improves matters
a bit. I suppose the 1) case could check if we already specified a
command at the end, and use that completion, but I'll leave that as an
exercise for now.
---
Completion/Zsh/Function/_zargs | 64 +++++++++++++++++++++++++++++-------------
1 file changed, 44 insertions(+), 20 deletions(-)
diff --git a/Completion/Zsh/Function/_zargs b/Completion/Zsh/Function/_zargs
index f1f87b4..c24b276 100644
--- a/Completion/Zsh/Function/_zargs
+++ b/Completion/Zsh/Function/_zargs
@@ -1,24 +1,48 @@
#compdef zargs -value-,-default-,-command-
-# atom smasher - jan 2011
-local arguments
+local arguments eofstr pos=$((CURRENT)) numeofs=0 ret=1 cmdpos=1
-arguments=( $arguments[@]
- '(--eof -e)'{--eof=,-e+}'[change the end-of-input-args string from "--" to eof-str]'
- '(--exit, -x)'{--exit,-x}'[exit if the size (see --max-chars) is exceeded]'
- '--help[print summary and exit]'
- '(--interactive, -p)'{--interactive,-p}'[prompt before executing each command line]'
- '(--max-args, -n)'{--max-args=,-n+}'[use at most max-args arguments per command line]'
- '(--max-chars, -s)'{--max-chars=,-s+}'[use at most max-chars characters per command line]'
- '(--max-lines, -l)'{--max-lines=,-l+}'[use at most max-lines of the input-args per command line]'
- '(--max-procs, -P)'{--max-procs=,-P+}'[run up to max-procs command lines in the background at once]'
- '(--no-run-if-empty, -r)'{--no-run-if-empty,-r}'[do nothing if there are no input arguments before the eof-str]'
- '(--null, -0)'{--null,-0}'[split each input-arg at null bytes, for xargs compatibility]'
- '(--replace, -i)'{--replace=,-i}'[substitute replace-str in the initial-args by each initial-arg]'
- '(--verbose, -t)'{--verbose,-t}'[print each command line to stderr before executing it]'
- '--version[print the version number of zargs and exit]'
-)
+#this doesn't handle '--' on the command line, only --
+#it also by extension doesn't handle eofstr being the empty string
+#it also also doesn't handle eofstr being -e or --eof, and everything will
+# probably also be confused if the command at the end takes a -e, --eof= or --
+eofstr=${${${${words[(r)(--eof=*|-e*)]}#--eof=}#-e}:---}
+while {
+ pos=$(( words[(b:pos-1:I)$eofstr] ))
+ (( numeofs == 0 )) && (( cmdpos = pos ))
+ (( pos )) && (( numeofs++ ))
+ (( pos ))
+} {}
+case $numeofs in
+ 0)
+ #zargs arguments
+ arguments=(
+ '(--eof -e)'{--eof=,-e+}'[change the end-of-input-args string from "--" to eof-str]'
+ '(--exit, -x)'{--exit,-x}'[exit if the size (see --max-chars) is exceeded]'
+ '--help[print summary and exit]'
+ '(--interactive, -p)'{--interactive,-p}'[prompt before executing each command line]'
+ '(--max-args, -n)'{--max-args=,-n+}'[use at most max-args arguments per command line]'
+ '(--max-chars, -s)'{--max-chars=,-s+}'[use at most max-chars characters per command line]'
+ '(--max-lines, -l)'{--max-lines=,-l+}'[use at most max-lines of the input-args per command line]'
+ '(--max-procs, -P)'{--max-procs=,-P+}'[run up to max-procs command lines in the background at once]'
+ '(--no-run-if-empty, -r)'{--no-run-if-empty,-r}'[do nothing if there are no input arguments before the eof-str]'
+ '(--null, -0)'{--null,-0}'[split each input-arg at null bytes, for xargs compatibility]'
+ '(--replace, -i)'{--replace=,-i}'[substitute replace-str in the initial-args by each initial-arg]'
+ '(--verbose, -t)'{--verbose,-t}'[print each command line to stderr before executing it]'
+ '--version[print the version number of zargs and exit]'
+ )
+ _arguments -S -s $arguments[@] && ret=0
+ ;;
+ 1)
+ #argument list for command
+ _files && ret=0
+ ;;
+ *)
+ #command and command arguments
+ shift cmdpos words
+ (( CURRENT -= cmdpos ))
+ _normal
+ ;;
+esac
-_arguments -S -s $arguments[@]
-
-_command_names -e
+return ret
--
2.4.0
Messages sorted by:
Reverse Date,
Date,
Thread,
Author