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

Re: completion help



On Apr 14, 10:08am, Michael Drzal wrote:
}
} % ssh host<TAB>
} host host.regular host.inband host.outofband
} 
} I realize that I could enumerate all of the possible hosts with the
} hosts style, but this seems like overkill.  Is there some way that I
} could do something like:
} 
} zstyle context domains domain1 domain2 domain3 ...
} 
} and get the effect that I'm looking for?

zstyle -e ':completion:*:(ssh|scp):*' hosts \
    'reply=( ${${words[CURRENT]%.*}#*@}.{domain1,domain2,domain3,...} )'

This will complete the domains directly (with a leading dot) if you
have't already typed the host part.  A conditional test on
$words[CURRENT] could be added to set reply only if there is already
at least one dot.  Additional complexity is of course possible.  You
might also want to put the list of domain names in a variable where
it's more easily edited:

host_domains=( domain1 domain2 domain3 ... )

zstyle -e ':completion:*:(ssh|scp):*' hosts \
    '[[ $words[CURRENT] = *.* ]] && 
     reply=( ${${words[CURRENT]%.*}#*@}.${^host_domains} )'

If you're starting to get really complex conditions, I suggest putting
them into a function and replacing the string value of the style with
a call to the function.



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