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

Re: rsync --progress stops completion



On Sep 21, 10:27pm, Yuri D'Elia wrote:
}
} Any obvious problems you can spot?

Declaring "local -a _complete_fallback_precmd" will mean that it goes
away after the autoload of _complete_fallback is finished; so after
that point you're just manipulating an undeclared global.

Also I don't think the assignments to/from precmd_functions are going
to do what you want, and there's no reason to do anything if the
context isn't "command" (is there?).

Here's a version with those repairs, and below that a suggested change
that goes back to tabbing twice.

## --- 8< --- snip --- 8< --- 
#autoload
typeset -gH _complete_fallback_precmd

(( $+functions[add-zsh-hook] )) || autoload add-zsh-hook

_complete_fallback_cleanup()
{
  add-zsh-hook -D precmd _complete_fallback\*
  _complete_fallback_precmd=''
}

_complete_fallback()
{
  [[ $compstate[context] = command && $CURRENT -gt 2 ]] || return 1

  if [[ -n $_complete_fallback_precmd || $LASTWIDGET = *complete* ]]
  then
    if [[ -z $_complete_fallback_precmd ]]
    then
      _complete_fallback_precmd=precmd
      add-zsh-hook precmd _complete_fallback_cleanup
      compadd -x "fallback: enabled"
      return 0
    fi

    words=("$words[1]" "${(@)words[$CURRENT,-1]}")
    CURRENT=2
    _compskip=default
    _complete
  fi
}

_complete_fallback "$@"
## --- 8< --- snip --- 8< --- 

Here's the two-tab version:

## --- 8< --- snip --- 8< --- 
#autoload
typeset -gH _complete_fallback_precmd

(( $+functions[add-zsh-hook] )) || autoload add-zsh-hook

_complete_fallback_cleanup()
{
  add-zsh-hook -D precmd _complete_fallback\*
  _complete_fallback_precmd=''
}

_complete_fallback()
{
  [[ $compstate[context] = command && $CURRENT -gt 2 ]] || return 1

  if [[ -z $_complete_fallback_precmd || $LASTWIDGET != *complete* ]]
  then
    _complete_fallback_precmd=precmd
    add-zsh-hook precmd _complete_fallback_cleanup
    compadd -x "Completion failed, press ${${(V)KEYS}:s/\\t/TAB} for fallbacks"
    return 0
  fi

  if [[ $LASTWIDGET = *complete* ]]
  then
    words=("$words[1]" "${(@)words[$CURRENT,-1]}")
    CURRENT=2
    compadd -x "fallback: enabled"
    _compskip=default
    _complete
  fi
}

_complete_fallback "$@"
## --- 8< --- snip --- 8< --- 



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