Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Fun zsh trick for today
- X-seq: zsh-users 3154
- From: Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxxxxxx (Zsh users list)
- Subject: Re: Fun zsh trick for today
- Date: Wed, 14 Jun 2000 15:15:58 +0100
- In-reply-to: "Your message of Wed, 14 Jun 2000 09:57:34 EDT." <20000614095734.E27844@xxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxxxxxx; run by ezmlm
> I'm no Bart-guru, but here's an application of his trick that I find useful
> for the new completion system:
>
> zmodload -i zsh/mapfile
> hosts=(${(@)${(@)${(M)${(f)mapfile[$HOME/.ssh/known_hosts]}:#[^0-9]*}%%\ *}%%
> ,*})
> zstyle ':completion:*:hosts' hosts $hosts
In something like this there's really no gain over doing it using more
ordinary zsh methods, i.e. with $(<...), which doesn't require a module.
Plus you don't need all those (@)'s once parameter substitution already has
arrays, which (f) provides. The only trick here is using double quotes to
get whole lines for splitting. I think the following should work in 3.0.8
(can't quite remember if the trick of putting double quotes in the middle
made its way back --- if not, put quotes around the lot and put (@)'s at
the front of all the parameter substitutions).
hosts=(${${${${(f)"$(<$HOME/.ssh/known_hosts)"}:#[^0-9]*}%%\ *}%%,*
})
or
hosts=("${(@)${(@)${(@M)${(@f)"$(<$HOME/.ssh/known_hosts)"}:#[^0-9]*}%%\ *}%%,*
}")
--
Peter Stephenson <pws@xxxxxxxxxxxxxxxxxxxxxxxxx>
Cambridge Silicon Radio, Unit 300, Science Park, Milton Road,
Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070
Messages sorted by:
Reverse Date,
Date,
Thread,
Author