Expand command line exclude pattern with zsh

喜夏-厌秋 提交于 2019-12-24 09:40:12

问题


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?


回答1:


Add multiple --ignore commands. For instance:

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



回答2:


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.



来源:https://stackoverflow.com/questions/37037307/expand-command-line-exclude-pattern-with-zsh

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!