Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
using precmd() to get hostnames out of commands
- X-seq: zsh-users 4065
- From: Alan Third <alan@xxxxxxxxxx>
- To: zsh-users mailing list <zsh-users@xxxxxxxxxxxxxx>
- Subject: using precmd() to get hostnames out of commands
- Date: Sun, 29 Jul 2001 14:57:15 +0100
- Mail-followup-to: Alan Third <alan@xxxxxxxxxx>, zsh-users mailing list <zsh-users@xxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
Right, a while ago I decided that I wanted my hostname completion to
include any hostnames that I typed on the command line during a
session so I could do things like:
grover:/home/alan>ping penglet.org
<snip>
grover:/home/alan>ssh pen<tab>
So I came up with this:
iplegal()
{
if [[ $1 == ([1-9]||[1-9][0-9]||1[0-9][0-9]||[2[0-4][0-9]||25[0-5]).\
([0-9]||[1-9][0-9]||1[0-9][0-9]||[2[0-4][0-9]||25[0-5]).\
([0-9]||[1-9][0-9]||1[0-9][0-9]||[2[0-4][0-9]||25[0-5]).\
([0-9]||[1-9][0-9]||1[0-9][0-9]||[2[0-4][0-9]||25[0-5]) ]]
then
echo legal
else
echo illegal
fi
}
precmd()
{
# add any hostnames from the last command to the
# hostname completion array
lastargs=(`fc -ln -1`)
for stuff in $lastargs
do
if [[ $stuff == (*.org||*.com||*.net||*.edu||*.??~*.\
[[:digit:]][[:digit:]]) || `iplegal $stuff` == legal ]]
then
hosts=($hosts $stuff)
zstyle ':completion:*:hosts' hosts $hosts
fi
done
}
It also recognises IPs and sticks them in too.
Is there a better way to do this?
Thanks.
--
Alan Third
Cows go moo!
Messages sorted by:
Reverse Date,
Date,
Thread,
Author