zsh-workers
 help / color / mirror / code / Atom feed
* PATCH: Add new option -s to compdef
@ 2011-03-28 15:12 Mikael Magnusson
  2011-03-28 16:53 ` Peter Stephenson
  0 siblings, 1 reply; 4+ messages in thread
From: Mikael Magnusson @ 2011-03-28 15:12 UTC (permalink / raw)
  To: zsh workers

I wanted to do this
compdef 'words[1]=./configure;_configure' c m
having read this in the man page
  The function argument may alternatively be  a  string  containing  any
  shell  code.   The string will be executed using the eval builtin com‐
  mand to generate completions.

However, it doesn't work because the name=service check takes
precedence. Thus I came up with the following which lets you simply
say
compdef 'words[1]=./configure;_configure' c m
to override the check

Does "almost any shell code" sound too silly? :)

http://cgit.mika.l3ib.org/cgit/zsh-cvs/commit/?id=63127c2be013

diff --git a/Completion/compinit b/Completion/compinit
index aa42a12..e907114 100644
--- a/Completion/compinit
+++ b/Completion/compinit
@@ -229,7 +229,7 @@ comppostfuncs=()
 #   delete the definitions for the command names `bar' and `baz'

 compdef() {
-  local opt autol type func delete new i ret=0 cmd svc
+  local opt autol type func delete shellcode new i ret=0 cmd svc
   local -a match mbegin mend

   emulate -L zsh
@@ -242,7 +242,7 @@ compdef() {
     return 1
   fi

-  while getopts "anpPkKd" opt; do
+  while getopts "anpPkKds" opt; do
     case "$opt" in
     a)    autol=yes;;
     n)    new=yes;;
@@ -263,6 +263,7 @@ compdef() {
 	  fi
 	  ;;
     d) delete=yes;;
+    s) shellcode=yes;;
     esac
   done
   shift OPTIND-1
@@ -276,7 +277,7 @@ compdef() {
     # If the first word contains an equal sign, all words must contain one
     # and we define which services to use for the commands.

-    if [[ "$1" = *\=* ]]; then
+    if [[ -z "$shellcode" ]] && [[ "$1" = *\=* ]]; then
       while (( $# )); do
         if [[ "$1" = *\=* ]]; then
 	  cmd="${1%%\=*}"
diff --git a/Doc/Zsh/compsys.yo b/Doc/Zsh/compsys.yo
index 28dd5f2..8964eaa 100644
--- a/Doc/Zsh/compsys.yo
+++ b/Doc/Zsh/compsys.yo
@@ -447,7 +447,7 @@ directly.
 findex(compdef)
 cindex(completion system, adding definitions)
 startitem()
-xitem(tt(compdef) [ tt(-an) ] var(function names...) [ tt(-[pP])
var(patterns...) [ tt(-N) var(names...) ] ])
+xitem(tt(compdef) [ tt(-ans) ] var(function names...) [ tt(-[pP])
var(patterns...) [ tt(-N) var(names...) ] ])
 xitem(tt(compdef -d) var(names...))
 xitem(tt(compdef -k) [ tt(-an) ] var(function style key-sequences...))
 item(tt(compdef -K) [ tt(-an) ] var(function name style key-sequences ...))(
@@ -460,10 +460,12 @@ defined by `var(cmd1)tt(=)var(service)' lines in
tt(#compdef) files, as
 described above.  The argument for var(cmd) will be completed in the
 same way as var(service).

-The var(function) argument may alternatively be a string containing any
-shell code.  The string will be executed using the tt(eval) builtin
-command to generate completions.  This provides a way of avoiding having
-to define a new completion function.  For example, to complete
+The var(function) argument may alternatively be a string containing
+almost any shell code.  If the string contains an equal sign, the above
+will take precedence. The option -s may be used to specify the first
+argument is shell code. The string will be executed using the tt(eval)
+builtin command to generate completions.  This provides a way of avoiding
+having to define a new completion function.  For example, to complete
 files ending in `tt(.h)' as arguments to the command tt(foo):

 example(compdef '_files -g "*.h"' foo)


-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: Add new option -s to compdef
  2011-03-28 15:12 PATCH: Add new option -s to compdef Mikael Magnusson
@ 2011-03-28 16:53 ` Peter Stephenson
  2011-03-28 18:02   ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Stephenson @ 2011-03-28 16:53 UTC (permalink / raw)
  To: zsh workers

On Mon, 28 Mar 2011 17:12:59 +0200
> http://cgit.mika.l3ib.org/cgit/zsh-cvs/commit/?id=63127c2be013

This gives me a web page...

> diff --git a/Completion/compinit b/Completion/compinit

while this has got the whitespace screwed up.

Is there any chance of getting just a patch I can apply?

-- 
Peter Stephenson <pws@csr.com>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: Add new option -s to compdef
  2011-03-28 16:53 ` Peter Stephenson
@ 2011-03-28 18:02   ` Bart Schaefer
  2011-03-29  4:26     ` Mikael Magnusson
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2011-03-28 18:02 UTC (permalink / raw)
  To: zsh workers

On Mar 28,  5:53pm, Peter Stephenson wrote:
}
} Is there any chance of getting just a patch I can apply?

Also I was going to mention that in other places we typically have
used "-e" (mnemonic "eval") for things that allow quoted shell code
that will be executed later.  E.g. "zstyle -e", (e:...:), etc.

So I'd suggest "compdef -e" rather than -s.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: PATCH: Add new option -s to compdef
  2011-03-28 18:02   ` Bart Schaefer
@ 2011-03-29  4:26     ` Mikael Magnusson
  0 siblings, 0 replies; 4+ messages in thread
From: Mikael Magnusson @ 2011-03-29  4:26 UTC (permalink / raw)
  To: zsh workers

On 28 March 2011 20:02, Bart Schaefer <schaefer@brasslantern.com> wrote:
> On Mar 28,  5:53pm, Peter Stephenson wrote:
> }
> } Is there any chance of getting just a patch I can apply?

Oops, I forgot to click "patch" before copying the link, here's the
correct link to a version that uses -e instead.

http://cgit.mika.l3ib.org/cgit/zsh-cvs/patch/?id=4ab6dd5314

Or I can commit it myself.

> Also I was going to mention that in other places we typically have
> used "-e" (mnemonic "eval") for things that allow quoted shell code
> that will be executed later.  E.g. "zstyle -e", (e:...:), etc.
>
> So I'd suggest "compdef -e" rather than -s.

-- 
Mikael Magnusson


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2011-03-29  4:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-28 15:12 PATCH: Add new option -s to compdef Mikael Magnusson
2011-03-28 16:53 ` Peter Stephenson
2011-03-28 18:02   ` Bart Schaefer
2011-03-29  4:26     ` Mikael Magnusson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).