Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: custom script Bash completion



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