我正在使用强大的完成功能编写一些zsh函数。计算我的完成需要一些时间,我想使用完成缓存策略。从zsh手册(https://zsh.sourceforge.io/Doc/Release/Completion-System.html)中,我找到了这个代码片段
example_caching_policy () {
# rebuild if cache is more than a week old
local -a oldp
oldp=( "$1"(Nm+7) )
(( $#oldp ))
}我找不到关于(Nm+7)语法的任何解释,Nm是什么意思?通过尝试和错误,我可以发现,例如,Nms+1将将缓存策略更改为1秒,而Nmh+1将更改为1小时。但是我在哪里可以找到一般的(NmX+N)构造解释呢?同样,这一行(( $#oldp ))到底是什么意思?
发布于 2022-01-25 10:36:22
我可以解释一下(Nm+7)
man zshexpn,搜索Glob限定符
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代表NULL_GLOB,如果zsh不匹配,它将删除模式。
如果没有这个N选项,如果不匹配,它将打印一个错误。
有4个文件的示例
$ 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 lshttps://stackoverflow.com/questions/70843900
复制相似问题