使用 zsh 扩展命令行排除模式

Expand command line exclude pattern with zsh

我正在尝试将复杂的正则表达式作为忽略模式传递。我想忽略 locales/ 除了 locales/US/en/* 的所有子文件夹。我可能需要回退到使用 .agignore 文件,但我正在努力避免这种情况。

我正在使用 silver searcher(类似于 Ack、Grep)。我在终端中使用 zsh。

这非常有效并忽略了所有区域设置子文件夹 except locales/US:

ag -g "" --ignore locales/^US/ | fzf

我也想忽略所有 locales/US/* 除了 locales/US/en 我要的是这个,但是不行

ag -g "" --ignore locales/^US/^en | fzf

想法?

添加多个--ignore 命令。例如:

ag -g "" --ignore locales/^US/ --ignore locales/US/^en

以下也可以工作:

find locales/* -maxdepth 0 -name 'US' -prune -o -exec rm -rf '{}' ';'

Man Pages Documentation

-prune True; if the file is a directory, do not descend into it. If -depth is given, false; no effect. Because -delete implies -depth, you cannot usefully use -prune and -delete together.

-prune 可让您筛选出结果 (better description here)

-exec command ; Execute command; true if 0 status is returned. All following arguments to find are taken to be arguments to the command until an argument consisting of ';' is encountered. The string '{}' is replaced by the current file name being processed everywhere it occurs in the arguments to the command, not just in arguments where it is alone, as in some versions of find. Both of these constructions might need to be escaped (with a '\') or quoted to protect them from expansion by the shell. See the EXAMPLES section for examples of the use of the -exec option. The specified command is run once for each matched file. The command is executed in the starting directory. There are unavoidable security problems surrounding use of the -exec action; you should use the -execdir option instead.

-exec 允许您对任何结果执行命令 find returns.