-1

I'm writting some zsh functions using the powerful completion feature. The computation of my completions take some times and I want to make use of the completion caching policy. From the zsh manual (https://zsh.sourceforge.io/Doc/Release/Completion-System.html) I found this code snippet

example_caching_policy () {
    # rebuild if cache is more than a week old
    local -a oldp
    oldp=( "$1"(Nm+7) )
    (( $#oldp ))
}

I couldn't find any explanation on the (Nm+7) syntax, what does Nm means ? With try and error I could find out that for example Nms+1 would change the cache policy to 1 second, while Nmh+1 to 1 hour. But where can I find the general (NmX+N) construct explanation ? Same what does exactly means the line (( $#oldp )) ?

Brice.S
  • 47
  • 6

1 Answers1

1

I can explain the (Nm+7)

man zshexpn, search for Glob Qualifiers

a[Mwhms][-|+]n
    files accessed exactly n days ago.  Files accessed within the last n days are selected using a negative
    value for n (-n).  Files accessed more than n days ago are selected by a positive n  value  (+n).   Op‐
    tional  unit  specifiers  `M',  `w',  `h', `m' or `s' (e.g. `ah5') cause the check to be performed with
    months (of 30 days), weeks, hours, minutes or seconds instead of days, respectively.  An  explicit  `d'
    for days is also allowed.

    Any  fractional  part of the difference between the access time and the current part in the appropriate
    units is ignored in the comparison.  For instance, `echo *(ah-5)' would echo files accessed within  the
    last  five  hours,  while  `echo  *(ah+5)'  would  echo files accessed at least six hours ago, as times
    strictly between five and six hours are treated as five hours.

m[Mwhms][-|+]n
    like the file access qualifier, except that it uses the file modification time.

N stands for NULL_GLOB, if zsh matches nothing, it will remove the pattern.
Without this N option, if it matches nothing it will print an error.

Example with 4 files

$ touch lal # = updates file modification date to now
$ ls
lal  lil  lol  tut

$ ls l*(m+7)
lil  lol 
# files older than 7 days starting with l

$ ls l*(m-7)
lal 
# files younger than 7 days starting with l

$ ls l*(m+200)
zsh: no match
# no files older than 200 days

$ ls l*(Nm+200)
lal  lil  lol  tut
# N = NULL_GLOB made disappear the non-matching pattern so it's just ls
lolesque
  • 10,693
  • 5
  • 42
  • 42