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

Re: rsync --progress stops completion



On 09/21/2014 09:38 PM, Bart Schaefer wrote:
> You might be better off using "compadd -x" to display a message, but
> that only shows up if there's a completion listing.  Hmm.

After some testing, I got this:

#autoload
local -a _complete_fallback_precmd

_complete_fallback_cleanup()
{
  precmd_functions=_complete_fallback_precmd
  _complete_fallback_precmd=()
}

_complete_fallback()
{
  if [[ -n $_complete_fallback_precmd || $LASTWIDGET = *complete* ]]
  then
    if [[ -z $_complete_fallback_precmd ]]
    then
      _complete_fallback_precmd=precmd_functions
      precmd_functions+=( _complete_fallback_cleanup )
      compadd -x "fallback: enabled"
      return 0
    fi

    [[ $compstate[context] = command && $CURRENT -gt 2 ]] || return 1
    words=("$words[1]" "${(@)words[$CURRENT,-1]}")
    CURRENT=2
    _compskip=default
    _complete
  fi
}

_complete_fallback "$@"

===

When the hook is added, I display a message and then stop to make it
readable, as otherwise it's obliterated by the completion list. Felt a
bit odd in the beginning, since you need to press tab *again*, but it
gives you a chance to just accept/cancel the command if you're in doubt.
I like the behavior, as it makes obvious that the completion broke at
that point.

I also removed the local curcontext, since after
_complete_fallback_precmd is set, the context is already
:completion::complete-fallback:* due to the fact that _complete_fallback
is immediately entered.

Any obvious problems you can spot?




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