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

Re: rsync --progress stops completion



On 09/21/2014 07:20 PM, Bart Schaefer wrote:
> To permit zstyle customizations it might also be useful to set up the
> "compcontext" parameter and call _complete instead of "_normal -s".
> There aren't any good examples of this except Functions/Misc/nslookup.

So here's what I got so far:

============

#autoload

typeset -a _complete_fallback_precmd

_complete_fallback_cleanup()
{
  precmd_functions=_complete_fallback_precmd
  RPROMPT=$_complete_fallback_rprompt
}

_complete_fallback()
{
  if [[ $LASTWIDGET = *complete* || -n $_complete_fallback_precmd ]]
  then
    if [[ -z $_complete_fallback_active ]]
    then
      _complete_fallback_precmd=precmd_functions
      precmd_functions+=( _complete_fallback_cleanup )
    fi

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

_complete_fallback "$@"

============

First, I hook into "precmd_functions" to setup some cleanup actions. The
idea is that once fallback is active, it's immediately entered upon the
completion of another argument. I couldn't find a better way to perform
cleanup really.

This allows rsync --random something [tab] to immediately enter the
fallback if it was enabled at least once.

Then I just append "fallback" to curcontext, so that in theory if you
wanted to customize the fallback, you could match the style on
"*:fallback:*".

So then I tried to change the prompt so that I get an indicator that the
fallback is active. But changing PROMPT/RPROMPT inside the completer
doesn't redraw the prompt until the command is accepted. Is there a way
to force the prompt to be updated?




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