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

Re: Completion function directories



On Apr 27, 11:59am, Andrej Borsenkow wrote:
> Subject: RE: Completion function directories
> >
> > Much earlier, Sven wrote:
> > } [...] Andrej comes and says that we should put all the GNU commands
> > } on the side...
> >
> > This brings up a a question of whether we should have helper functions
> > for setting/testing the _is_gnu assoc, like happens now in _make and
> > _diff_options, or to set up the "standard completion environment" like
> > in _main_complete and _complete_help.
> 
> I am not sure I understand what do you mean under "standard completion
> environment" in this respect.

The two lines of setopts that have to appear at the top of each of several
of the completion functions to be sure all the globs and parameter refs
work as expected in all the rest of the functions those call.

My idea was to write a function:

    _standard_completer_setopts () {
	unsetopt localoptions	# This is the problem part
        setopt nullglob rcexpandparam extendedglob
        unsetopt markdirs globsubst shwordsplit nounset ksharrays
    }

Then there's only one place to edit if we ever need to change the setopts
used by all the completion scripts -- but the present unpredictable
behavior of `unsetopt localoptions' makes this idea unworkable.

> I believe, in all cases when it is
> possible we need automatic test for GNU utilities so, that completion
> really works "out of the box". And only when it's not possible - last
> resort like styles for particular command.

Following the same sort of suggestion as above, we'd have something like

    _detect_gnu () {
        (( $+_is_gnu )) || typeset -gA _is_gnu
        if (( ! $+_is_gnu[$1] ))
        then
                if [[ $(_call version "$@" </dev/null 2>/dev/null) = *GNU* ]]
                then
                        _is_gnu[$1]=yes 
                else
                        _is_gnu[$1]= 
                fi
        fi
	[[ $_is_gnu[$1] = yes ]]
    }

And then _make would use

	if _detect_gnu $words[1] -v -f /dev/null; then

and _diff_options would use

	if _detect_gnu $cmd -v; then

and so on for any other completion functions that needed to notice GNU.



Messages sorted by: Reverse Date, Date, Thread, Author