Expand command line exclude pattern with zsh

2019-07-25 10:05发布

I'm trying to pass a complicated regex as an ignore pattern. I want to ignore all subfolders of locales/ except locales/US/en/*. I may need to fallback to using a .agignore file, but I'm trying to avoid that.

I'm using silver searcher (similar to Ack, Grep). I use zsh in my terminal.

This works really well and ignores all locale subfolders except locales/US:

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

I also want to ignore all locales/US/* except for locales/US/en Want I want is this, but it does not work.

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

Thoughts?

标签: regex grep zsh ag fzf
2条回答
Emotional °昔
2楼-- · 2019-07-25 10:18

The following can work as well:

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 lets you filter out your results (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 lets you execute a command on any results find returns.

查看更多
姐就是有狂的资本
3楼-- · 2019-07-25 10:20

Add multiple --ignore commands. For instance:

ag -g "" --ignore locales/^US/ --ignore locales/US/^en
查看更多
登录 后发表回答