From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7242 invoked by alias); 26 Mar 2017 21:23:27 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 22616 Received: (qmail 12413 invoked from network); 26 Mar 2017 21:23:27 -0000 X-Qmail-Scanner-Diagnostics: from out1-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(66.111.4.25):SA:0(-0.7/5.0):. Processed in 2.465318 secs); 26 Mar 2017 21:23:27 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-0.7 required=5.0 tests=RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.1 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= fm1; bh=Inti+Ji4hJBIaMry21vmPEsldoYgFyScgWmgmCm8U6o=; b=N1b0Y7/5 y7hj/XfE1YSeDtLoJUh9FY3LCDGcvv+uMEtkQ5S6zMc6woOrB9xmLwDIYWG6I7lt QJJPFDtbROchmDw1kEPg0yUE2IcwzOIAmXZP2RlwleaTAkjMJYFJIbWZP2F0/2G2 spsplvVcLONh1tJDrloALzeuFClyLTJR5FR0dlVo8pAR6csHRWGJ+JGNNzmwJtxD 6hLcBSOLct5VwPgESFHSExEBRH+XNLOM1q9YTVKoxdnyk/dbZM3zaMRFjCpnYLq1 gHwI6cEGywpOc7SQPrsYHaLT55SIvJnceRCWYELIbSjSlSji4DXb9a6AwXWbzLNC JHyBuDY8iIw3tQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc:x-sasl-enc; s= fm1; bh=Inti+Ji4hJBIaMry21vmPEsldoYgFyScgWmgmCm8U6o=; b=bsMMZngT JW0TUq/PUKRCcwGj/Y2/fe6rtyjpl4VY/I/VN34LUvtRuhPTYiR+ruK5IJw+nD+3 L63ka2ZIxshLh41Eqgl3HbLjHTYA03MizX65pMQdoVOtZXpisc8pjtlBHQe1SCNK 7yoexGtfaTBSDT9ZuoGiWifC22zpRdfrr1XFNwDZpm2fQSxM2x1LK0H9D2wxL7Cg B2sNK7dJtIXLRSvwHysUwhszMdb6zDTeIW5RY/LfF4Chd+j9KJzTfKRXUjjvmzT4 r8aLeLxKZnHL+Wvy0ha7/U1Kzy8qFFNpnPgQf/I+8+bxGLtVQKdxr4oSc+5j1ECo Gu/7ZhKP0rrlBw== X-ME-Sender: X-Sasl-enc: haRwSC+VeM6B7dqcQLVaMq2Uo8smaBjoD13XdYwrhvrk 1490563395 Date: Sun, 26 Mar 2017 21:18:05 +0000 From: Daniel Shahaf To: Ray Andrews Cc: Zsh Users Subject: Re: spaces in filenames should be a crime. Message-ID: <20170326211805.GA8170@fujitsu.shahaf.local2> References: <0c1b9d89-edd0-a027-e2f1-d01c2d68fa4e@eastlink.ca> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <0c1b9d89-edd0-a027-e2f1-d01c2d68fa4e@eastlink.ca> User-Agent: Mutt/1.5.23 (2014-03-12) Ray Andrews wrote on Sun, Mar 26, 2017 at 13:22:24 -0700: > Gentlemen: > > This function: > > mostrecent () > { > ls -l ${(f)$( find . -type f -printf "%T@ %p\n" | sort -n | cut -d' > ' -f 2- | tail -n 1 )} > } You could replace the whole function with: mostrecent() { ls -l -- **/*(.om[1]) } That glob qualifier restricts the match to files ('.'), sorts them by modified date ('om'), and selects the first result ('[1]'). You can then use [1,3] to select several files. > Testing it on this dummy directory tree: > > ├── [ 0] a > ├── [4.0K] absolute junk > │ └── [ 0] junk > ├── [ 0] b > └── [ 0] c > > If the most recent file is under 'absolute junk', the function works, but it > requires the ' ${(f) ... ' treatment, otherwise it barfs at the space in the > directory name. However, if I change things to ' tail -n 3 " it shows me: > > ls: cannot access './a ./absolute junk/junk ./c': No such file or directory > > So whereas the ' ${(f) ' treatment fixes the one problem, it creates the > other, which is obviously that everything is one string. Can I have it both > ways? Protected spaces in the directory name, and still have multiple items > for the listing? I've done stuff like this before, but using arrays. > > Or can printf handle the situation by itself? As Vadim said, putting the $() in double quotes makes this example work. Another option here is to use find -print0 with ${(0)}. That only matter if you need to DTRT when filenames contain NL characters. Cheers, Daniel