From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 8330 invoked from network); 22 Jul 2005 09:17:05 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by ns1.primenet.com.au with SMTP; 22 Jul 2005 09:17:05 -0000 Received: (qmail 51345 invoked from network); 22 Jul 2005 09:16:56 -0000 Received: from sunsite.dk (130.225.247.90) by a.mx.sunsite.dk with SMTP; 22 Jul 2005 09:16:56 -0000 Received: (qmail 1746 invoked by alias); 22 Jul 2005 09:16:49 -0000 Mailing-List: contact zsh-users-help@sunsite.dk; run by ezmlm Precedence: bulk X-No-Archive: yes X-Seq: 9123 Received: (qmail 1735 invoked from network); 22 Jul 2005 09:16:48 -0000 Received: from news.dotsrc.org (HELO a.mx.sunsite.dk) (130.225.247.88) by sunsite.dk with SMTP; 22 Jul 2005 09:16:48 -0000 Received: (qmail 50265 invoked from network); 22 Jul 2005 09:16:48 -0000 Received: from wproxy.gmail.com (64.233.184.193) by a.mx.sunsite.dk with SMTP; 22 Jul 2005 09:16:43 -0000 Received: by wproxy.gmail.com with SMTP id i36so279998wra for ; Fri, 22 Jul 2005 02:16:42 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=OLlPKgXFd5nU9FoC19LKHn+yIj8idmEQMgKzUENiS16sEj8eC7ZGjEjnr1BEA4lGP4xbqsoNmOnJMWSjdqTLUuKsR4WUaaGqQ9u2pee3H9htNdjQRV6JYzwbmTpyjMKYjk9Iw131Nrw8RipOxgAlPsL8WeMze59t37skuPXHs4E= Received: by 10.54.73.15 with SMTP id v15mr1073290wra; Fri, 22 Jul 2005 02:16:42 -0700 (PDT) Received: by 10.54.69.9 with HTTP; Fri, 22 Jul 2005 02:16:42 -0700 (PDT) Message-ID: Date: Fri, 22 Jul 2005 11:16:42 +0200 From: J Reply-To: J To: Tyler Spivey Subject: Re: Help with paths and file sorting Cc: zsh-users@sunsite.dk In-Reply-To: <20050721222024.GA14060@fast.vc.shawcable.net> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <20050721222024.GA14060@fast.vc.shawcable.net> X-Spam-Checker-Version: SpamAssassin 3.0.4 (2005-06-05) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,RCVD_BY_IP autolearn=ham version=3.0.4 > 1. is there an easy way to take a filespec like: > /home/tyler/dir1/* > and go back a directory? so the spec is /home/tyler/*? What about ${${var%/*}%/*}/${var##*/} ? (assuming the filespec is in the variable var) This take the pattern, chops two path elements off the end, and then concatenates again the last path element of the pattern. > 2. is there a way of, once having an array of files obtained by the * glo= bbing operator, > to sort them by size, time, etc? Sure. Suppose you have an array "files" that contain the names of the files you want to sort. You can just go along the lines of tmp=3D\(\(${(pj:|:)files}\)\) files=3D(${~tmp}()) The first line constructs a glob pattern that matches all the file names that are in the original array ; note the double parentheses around it are there to force glob evaluation even when the array contains only one file. The second lines evaluates the glob pattern the first just constructed, so you can append any globbing qualifiers you want. The sort qualifiers are described in the 'globbing qualifiers' of the zsh manual. That being said, only use this kind of construct if you strictly want to keep exactly the same file names in your array. For a file manager, I'd imagine that you want to keep up-to-date with the files in the directory, so it may be a simpler and wiser choice to simply re-glob the files with the sort qualifiers you want, and it's not going to be any slower anyway. But there is a caveat : If one of the filenames have a character in it that can be interpreted as a pattern for globbing, it will, and that's not what you want. A solution to that is to quote the ${files} array with a (q) flag, but then spaces in filenames (or any other special char for that) would be quoted too in the ${tmp} array, meaning they won't match themselves because these quotes are not going to be removed by the ${~tmp} construct :/ So the best I can come up with is to quote every of the glob patterns manually, like tmp=3D\(\(${(pj:|:)${${${${${files//\*/\\\*}//\(/\\\(}//\|/\\\|}//\