From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7269 invoked from network); 14 Jun 2000 14:17:06 -0000 Received: from sunsite.auc.dk (130.225.51.30) by ns1.primenet.com.au with SMTP; 14 Jun 2000 14:17:06 -0000 Received: (qmail 7840 invoked by alias); 14 Jun 2000 14:16:32 -0000 Mailing-List: contact zsh-users-help@sunsite.auc.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 3154 Received: (qmail 7833 invoked from network); 14 Jun 2000 14:16:32 -0000 Date: Wed, 14 Jun 2000 15:15:58 +0100 From: Peter Stephenson Subject: Re: Fun zsh trick for today In-reply-to: "Your message of Wed, 14 Jun 2000 09:57:34 EDT." <20000614095734.E27844@scowler.net> To: zsh-users@sunsite.auc.dk (Zsh users list) Message-id: <0FW500709EALIK@la-la.cambridgesiliconradio.com> Content-transfer-encoding: 7BIT > 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 Cambridge Silicon Radio, Unit 300, Science Park, Milton Road, Cambridge, CB4 0XL, UK Tel: +44 (0)1223 392070