首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >解释了Zsh完成缓存策略

解释了Zsh完成缓存策略
EN

Stack Overflow用户
提问于 2022-01-25 05:40:42
回答 1查看 338关注 0票数 -1

我正在使用强大的完成功能编写一些zsh函数。计算我的完成需要一些时间,我想使用完成缓存策略。从zsh手册(https://zsh.sourceforge.io/Doc/Release/Completion-System.html)中,我找到了这个代码片段

代码语言:javascript
复制
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 ))到底是什么意思?

EN

回答 1

Stack Overflow用户

发布于 2022-01-25 10:36:22

我可以解释一下(Nm+7)

man zshexpn,搜索Glob限定符

代码语言:javascript
复制
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个文件的示例

代码语言:javascript
复制
$ 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
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70843900

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档