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

Re: Force file completion when hitting TAB twice



On Thu, 17 Dec 2009 17:58:08 +0100
"Yuri D'Elia" <wavexx@xxxxxxxxxxxx> wrote:
> Hi everyone. I'm trying to customize the completion of zsh so that:
> 
> * when I hit TAB the default _complete completer is used.
> * if no completions are available, I get a beep.
> * if I hit TAB again, or hit TAB twice, I get a _files completer
>   (offering me to complete filenames regardless of the context).

Try this and let us know how you get on...  $LASTWIDGET test is
unsophisticated but probably covers the most obvious cases.


_complete_failed() {
  # Only complete if first attempt at completion failed.
  # Usage:
  #   zstyle ':completion:*' completer _complete _complete-failed
  #   zstyle ':completion:complete-failed:*' completer <your-completers>

  if [[ $LASTWIDGET = *complete* && -z $_complete_failed_active ]]; then
    local _complete_failed_active=1
    local -a completers
    local curcontext="complete-failed:::"
    _main_complete "${completers[@]}"
  fi
}
zstyle ':completion:*' completer _complete _complete-failed
zstyle ':completion:complete-failed:*' completer _files


-- 
Peter Stephenson <pws@xxxxxxx>            Software Engineer
Tel: +44 (0)1223 692070                   Cambridge Silicon Radio Limited
Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, UK


Member of the CSR plc group of companies. CSR plc registered in England and Wales, registered number 4187346, registered office Churchill House, Cambridge Business Park, Cowley Road, Cambridge, CB4 0WZ, United Kingdom



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