__pycache__
我在我的git
仓库和vi
Wildmenu中忽略了。这些目录污染我的工作流程的最后一个地方是在递归地 grep 项目文件时以及tab在命令行上使用自动完成功能时。
有没有办法配置命令行工具,例如grep
和bash-completion
来普遍忽略目录?
bash
您可以通过设置来使文件通配丢弃__pycache__
:
$ export GLOBIGNORE=__pycache__
Run Code Online (Sandbox Code Playgroud)
现在如果你发出:
$ ls __*
ls: cannot access __*: No such file or directory
Run Code Online (Sandbox Code Playgroud)
还bash
可以使用FIGNORE
环境变量来跳过文件后缀。它可以用来稍微过滤目录......
$ mkdir __pycache__
$ export FIGNORE=__pycache__
Run Code Online (Sandbox Code Playgroud)
然后发出时:
$ ls __
tab
将完成到
$ ls __pycache__
但是,如果它带有前缀(例如使用路径):
$ ls ./__
tab
它不会完成。
您可以使用别名grep
来排除__pycache__
目录:
alias grep='grep --exclude-dir="__pycache__"'
Run Code Online (Sandbox Code Playgroud)
您还可以使用 Madhavan Kumar 的答案来更改您想要过滤的命令的完成度grep
和其他命令,但不要忘记它们必须在 rc 文件中定义并在 source 之后获取bash_completion
,以应用您的覆盖。
FIGNORE
A colon-separated list of suffixes to ignore when performing filename
completion (see READLINE below). A filename whose suffix matches one of
the entries in FIGNORE is excluded from the list of matched filenames. A
sample value is ".o:~".
GLOBIGNORE
A colon-separated list of patterns defining the set of filenames to
be ignored by pathname expansion. If a filename matched by a pathname
expansion pattern also matches one of the patterns in GLOBIGNORE, it is
removed from the list of matches.
Run Code Online (Sandbox Code Playgroud)