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

Re: Completion of CLI parameters



On Apr 29,  1:56pm, Peter Stephenson wrote:
}
} autoload -U insert-args-of
} zle -N insert-args-of
} bindkey '^x^a' insert-args-of

Oliver would say this was crying out to be a _generic completer; here's
a trivial stab at one.  However, the right thing would be for _expand to
recognize a zstyle -- perhaps named "expander" -- that would supply a
function to produce expansions, and to try calling that before falling
back on the usual shell expansions.  That way we'd get the full power of
all the other styles recognized by _expand.

The following suffers from the usual problems of menus that may contain
multi-line structures, I haven't done anything to address that.

#autoload
# Name this file expand-args-of and place it in a $fpath directory, and
# then add these commands to .zshrc:
#  zle -C expand-args-of complete-word _generic
#  zstyle ':completion:expand-args-of::::' completer expand-args-of
#  bindkey '^x^a' expand-args-of

local pat=$words[CURRENT]
local -a exp

if ((CURRENT > 1))
then
  # Remove the first * here to match on command name only
  exp=( $history[(R)*${(q)pat}*] )
  exp=( ${exp#*[[:space:]]} )
else
  exp=( $history[(R)${(q)pat}*] )
fi
compadd -UQ -a exp
compstate[insert]=menu

#end of expand-args-of

-- 
Bart Schaefer                                 Brass Lantern Enterprises
http://www.well.com/user/barts              http://www.brasslantern.com

Zsh: http://www.zsh.org | PHPerl Project: http://phperl.sourceforge.net   



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