zsh-users
 help / color / mirror / code / Atom feed
* list last modified files
@ 2015-08-19 21:59 rooom
  2015-08-19 23:16 ` Vin Shelton
  2015-08-20  4:33 ` Bart Schaefer
  0 siblings, 2 replies; 13+ messages in thread
From: rooom @ 2015-08-19 21:59 UTC (permalink / raw)
  To: zsh-users

Hi,

I'm trying to write a function which lists 10 most recent files from given sets (not only directories), something like trivial `alias lt=ls -lat | head -n 10`, but better.

It should work like

lt                              # list 10 recent files from .
lt dir                          # list 10 recent files from dir/
lt dir1 file1 dir2/file* dir3   # list 10 recent files from a given sum of inputs


Here is my solution so far, which I think is overcomplicated and iffy:

lt() {ls -Adlt -- "${^@:-.}"(Ne:'[[ -d $REPLY ]] && reply=($REPLY/*(DNomon[1,10])) || true':) | head -n 10}

Here how it should work:
For each argument check if it is directory, and in that case return 10 most recent modified files from that directory, then add other arguments to the list (files) and ignore all non-file arguments (N). After all pass generated set to the 'ls' command which sorts it on modification time and finally pass to 'head -n 10'.


Several question:

1. First of all I cannot understand why do I need a command "true" to list properly arguments which are  not directories. I can put there other command as well like 'echo >/dev/null', but 'true' is simplest I could find (for example ':' doesn't work). From my basic understanding no command should be needed to properly handle 'lt file'.

2. I would like to get rid of external `head -n 10` command and use glob qualifiers instead, but as you can see there are already two nested qualifier lists, and I can't see a way to put one more after all of that just to take (om[1,10]).

3. When I run it with only non-existing files like 'lt nonexistingfile' then it prints single dot '.'. I would prefer to print error from 'ls' command like "ls: cannot access...". Note that I cannot remove (N) qualifier because zsh steps in with its own errors - I want zsh to pass argument to 'ls' as it is in case it cannot find files.


Hope it's not too long,
thanks in advance


^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2015-08-23 21:45 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-19 21:59 list last modified files rooom
2015-08-19 23:16 ` Vin Shelton
2015-08-20  4:33 ` Bart Schaefer
2015-08-20  5:20   ` Mikael Magnusson
2015-08-20 13:08   ` rooom
2015-08-20 13:29     ` Peter Stephenson
2015-08-20 15:34       ` Bart Schaefer
2015-08-20 15:55         ` Peter Stephenson
2015-08-20 17:13           ` Bart Schaefer
     [not found]         ` <20150820165552.2b5ec817__22391.7863135741$1440086232$gmane$org@pwslap01u.europe.root.pri>
2015-08-20 16:42           ` Stephane Chazelas
2015-08-20 17:09             ` Bart Schaefer
2015-08-23 20:35     ` ZLE: missing edit-buffer widget rooom
2015-08-23 21:45       ` Bart Schaefer

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).