Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: custom script Bash completion
- X-seq: zsh-users 18138
- From: Thomas Ballinger <tom@xxxxxxxxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: custom script Bash completion
- Date: Sun, 10 Nov 2013 16:34:24 -0500
- Cc: zsh-users <zsh-users@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed;        d=gmail.com; s=20120113;        h=mime-version:sender:in-reply-to:references:from:date:message-id         :subject:to:cc:content-type;        bh=XYaDOdukqYpkD9Vy0CRP9kRpYc+pB0YkmClCruXX7DA=;        b=NRf2IrfqcVPt5kHODpcOJnDzE03Ij9D2sQ4sf25jMqMxCsnjPD7sAN0lnpMumLnQf+         4U+L/YEiq64OCxB9f7g1lEgpnRBZAD7jZfg2LLBbP8XDM++wcjJtYp0QjbvnDDcx2xoy         PWtGN57Ai2imYaJL7mxh4nTxAOHYDKB/FuJKeBqPJmAMRPymyHWEj/MqP7fHOuyuDDds         gBQAaygmEXt8GL5F9eST9cUCbfxa/Cwrg4ruNV7OW6rRs1tuSY6DqXzB03FRqDJaoCQu         2ZrCiPOFuaY9kFsC9jdrrdPfX3npvRU0rHFNMCUlVJK66kHlTYOnsXSOCH2336i0xfy0         Kfxg==
- In-reply-to: <131110122530.ZM21629@torch.brasslantern.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CABb6=DWg_P+E+WvRzxZPnWDRN2jbL1Xh3P6tAMdHx+pmvCTdMA@mail.gmail.com> <131110102458.ZM21475@torch.brasslantern.com> <CABb6=DUEE3Zf_z2+bK65oSCuA7fq=SigPqt0Q+2b+5ge1YLrkw@mail.gmail.com> <131110122530.ZM21629@torch.brasslantern.com>
- Sender: thomasballinger@xxxxxxxxx
Thanks very much Bart.
I regret I can't be this volunteer at this time, but best of luck if anyone
takes it on. One of these days I'll learn to write a real zsh completion
script and use that instead :)
Tom
On Sun, Nov 10, 2013 at 3:25 PM, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>wrote:
> 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
>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author