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

Re: expand-cmd-path

Andy Spiegl wrote:

> While playing around with zle's "expand-cmd-path" I found that I'd like a
> different behavior of it (similar to tcsh).  I'd prefer if it didn't expand
> the first word/command on the input line, but the word before the cursor.
> Is that possible somehow?
> And I noticed that it does not expand aliases.  Is that intended?  Can it
> be changed?

Why not write your own little widget function? Like so:

  expand-last-word() {
    local word="${(M)LBUFFER%%[^ 	\;\|\{\}]##}" exp

    if (( $+commands[$word] )); then
    elif (( $+aliases[$word] )); then

    [[ -n "$exp" ]] && LBUFFER="${LBUFFER%$word}$exp"
  zle -N expand-last-word
  bindkey ... expand-last-word

Plus obvious improvements: The pattern in the first line should match
only thos characters that should be considered part of the word. If
the cursor is after a space (or other non-word characters) it could
search back for the word to expand. It could append a space to the
string inserted. Etc.


Sven Wischnowsky                         wischnow@xxxxxxxxxxxxxxxxxxxxxxx

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