zsh 完成标签顺序匹配模式

zsh 完成标签顺序匹配模式

是否可以使用匹配模式而不是ignored-patterstag-order

我想在第一次尝试时尝试一组自定义的有限匹配完成而不带前缀,如下所示:

$ man <Tab>
man info zshall

这是一个简化的示例。我想对 git 做同样的事情。我当前的风格依赖于一组特定的别名或要忽略的命令参数,这并不理想:

zstyle ':completion:*:complete:git:*' force-list  always
zstyle ':completion:*:complete:git:*' tag-order \
  'main-porcelain-commands:-freq:frequently\ used\ commands aliases'
zstyle ':completion:*:complete:git:*:main-porcelain-commands-freq' \
  ignored-patterns '(am|archive|bisect|bundle|clean|cherry-pick|citool|fetch|gc|gui|ls-files|log|notes|range-diff|show|stash|status|submodule|subtree|worktree)*'

这表明:

$ git <Tab>
add                -- add file contents to index
ai                 -- alias for 'add --interactive'
amend              -- alias for 'commit --amend --reuse-message=HEAD'
branch             -- list, create, or delete branches
checkout           -- checkout branch or paths to working tree
clone              -- clone repository into new directory
commit             -- record changes to repository
ctags              -- alias for '!.git/hooks/ctags'
describe           -- show most recent tag that is reachable from a commit
df                 -- alias for 'diff --staged'
diff               -- show changes between commits, commit and working tree, etc.
format-patch       -- prepare patches for e-mail submission
graph              -- alias for 'log --graph --oneline --decorate'
grep               -- print lines matching a pattern
init               -- create empty git repository or re-initialize an existing one
ls                 -- alias for 'ls-files'
merge              -- join two or more development histories together
mv                 -- move or rename file, directory, or symlink
pull               -- fetch from and merge with another repository or local branch
push               -- update remote refs along with associated objects
rebase             -- forward-port local commits to the updated upstream head
res                -- alias for 'reset --soft HEAD^'
reset              -- reset current HEAD to specified state
revert             -- revert existing commits
rm                 -- remove files from the working tree and from the index
shortlog           -- summarize git log output
st                 -- alias for 'status --short --untracked-files=no'
tag                -- create, list, delete or verify tag object signed with GPG

我想知道是否有必要忽略所有内容,然后使用fake-always,或者我是否可以在 中使用负查找ignored-patterns,或者我是否应该编写一个自定义完整函数来选择系统上实际存在的几个手册页,并且首先使用该自定义标签。

答案1

您可以在以下位置进行否定查找ignored-patterns:使用单个模式,该模式使用^否定运算符。 (extended_glob在完成期间始终启用,但我setopt extended_glob无论如何建议,因为它在完成之外也很有用。)

zstyle ':completion:*:complete:git:*:main-porcelain-commands-freq' \
  ignored-patterns '^(add|branch|…)'

相关内容