2

Is it possible to use matching patterns instead of ignored-patters in tag-order?

I'd like to try a custom limited set of matching completions on the first try without a prefix, like this:

$ man <Tab>
man info zshall

This is a simplified example. I'd like to do the same for git. My current style relies on a specific set of aliases or command arguments to be ignored, which is not ideal:

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)*'

which shows:

$ 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

I'd like to know if it is necessary to ignore everything, and then use fake-always, or if I could use a negative lookup in ignored-patterns, or else if I should write a custom complete function to select few manual pages that are actually on the system and use that custom tag first.

1

You can have a negative lookup in ignored-patterns: use a single pattern which uses the ^ negation operator. (extended_glob is always enabled during completion, but I recommend setopt extended_glob anyway because it's also useful outside of completion.)

zstyle ':completion:*:complete:git:*:main-porcelain-commands-freq' \
  ignored-patterns '^(add|branch|…)'
  • thanks! I was confusing it with (?!regex). – Bart Oct 22 '19 at 11:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.