zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users <zsh-users@zsh.org>
Subject: Re: custom script Bash completion
Date: Sun, 10 Nov 2013 12:25:30 -0800	[thread overview]
Message-ID: <131110122530.ZM21629@torch.brasslantern.com> (raw)
In-Reply-To: <CABb6=DUEE3Zf_z2+bK65oSCuA7fq=SigPqt0Q+2b+5ge1YLrkw@mail.gmail.com>

On Nov 10,  2:09pm, Thomas Ballinger wrote:
}
} [...] completion suggestions are still filtered though by "values
} that the user has typed the first letters of," preventing the fuzzy
} completion I'd written from taking effect:

Zsh completion assumes that the completion function is going to produce
all possible words that could appear at that position on the command
line; the internals then perform the filtering to match against the
partial word that is already present if any.  It was our feeling at the
time that it was far too much to expect every completion function author
to consider details such as whether the cursor was in the middle of the
word, etc.  The "compadd -U" option was created to enable authors to
have that degree of control, but it's not the default and it's not used
in the emulation functions defined by bashcompinit.

} I imagine I need to turn off some zsh completion feature for
} this completion?

I think you're going to have to replace bashcompinit with a slightly
edited version.  Perhaps if we get a volunteer to update bashcompinit,
that person can figure out how to make this optional.  In any case,
according to comments in bashcompinit the diff below might be what you
need.

I threw in making "complete -C" pass the same args as "complete -F".

diff --git a/Completion/bashcompinit b/Completion/bashcompinit
index 902fa88..e2b3597 100644
--- a/Completion/bashcompinit
+++ b/Completion/bashcompinit
@@ -26,7 +26,7 @@ _bash_complete() {
       compset -S '/*' && matches=( ${matches%%/*} )
       compadd -Q -f "${suf[@]}" -a matches && ret=0
     else
-      compadd -Q "${suf[@]}" -a matches && ret=0
+      compadd -U -Q "${suf[@]}" -a matches && ret=0
     fi
   fi
 
@@ -137,7 +137,10 @@ compgen() {
 	unsetopt nullglob
       ;;
       W) results+=( ${(Q)~=OPTARG} ) ;;
-      C) results+=( $(eval $OPTARG) ) ;;
+      C)
+        local -a args
+        args=( "${words[0]}" "${@[-1]}" "${words[CURRENT-2]}" )
+        results+=( $(eval $OPTARG "${args[@]}") ) ;;
       P) prefix="$OPTARG" ;;
       S) suffix="$OPTARG" ;;
       X)
@@ -152,7 +155,7 @@ compgen() {
   
   # support for the last, `word' option to compgen. Zsh's matching does a
   # better job but if you need to, comment this in and use compadd -U
-  # (( $# >= OPTIND)) && results=( "${(M)results[@]:#${@[-1]}*}" )
+  (( $# >= OPTIND)) && results=( "${(M)results[@]:#${@[-1]}*}" )
 
   print -l -r -- "$prefix${^results[@]}$suffix"
 }

-- 
Barton E. Schaefer


  reply	other threads:[~2013-11-10 20:25 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-11-10 16:14 Thomas Ballinger
2013-11-10 18:24 ` Bart Schaefer
2013-11-10 19:09   ` Thomas Ballinger
2013-11-10 20:25     ` Bart Schaefer [this message]
2013-11-10 21:34       ` Thomas Ballinger
2013-11-10 23:18   ` Chet Ramey
2013-11-11  2:12     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=131110122530.ZM21629@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).