git-annex/ tips/ ZSH completion

ZSH users, here's some good news: after 2 years of silence, the completion function for git-annex has been updated. It now supports all git-annex commands (as of 5.20140517) and has many improvements for completing arguments, remotes, groups, and backends.

To install it:

1. make sure your have Python 3 installed (as `python3` somewhere in your `$PATH`; tested with 3.4, should work with 3.2+)
2. get it from GitHub
3. copy `_git-annex` to somewhere in your `$fpath` (I use `$HOME/.config/zsh/completion`)
4. run `autoload -U path/to/_git-annex`
5. type `git annex <TAB>`

This is very far from being perfect, but it's (IMHO) better than nothing. If you have any issue or suggestion, please tell me!

Many thanks to Frank Terbeck and Valentin Haenel, the original authors of this completion function (source).

comment 2

Well, the code that generates the zsh completions could always be improved. https://github.com/pcapriotti/optparse-applicative/issues

I don't really understand why completing options before filenames makes it unusable. It means that "git-annex tabtabtab" cycles through options first, but if you type part of the filename tab will complete the rest. It does seem that someone else agrees with you though, as they filed this issue: https://github.com/pcapriotti/optparse-applicative/issues/173

Comment by joey — Wed Oct 29 14:05:27 2025
comment 4
Doesn't work so well for me. The hand-build one performs way better in terms of clearness and efficiency. It groups the suggestions instead of sorting them by name and it prints a description for each command. But most importently, it does only suggest switches when `-` was typed and completes file names otherwise. The auto generated one (at least the one that is shipped with the Arch Linux package) puts the file names last, which makes it unusable.
Comment by Lykos153 — Wed Oct 29 14:05:27 2025
comment 4
Well I guess that depends on habit/workflow. I often let tab completion show me the directory content before beginning to type. Thanks for the links, I'll look into it (though I have no experience with Haskell yet).
Comment by Lykos153 — Wed Oct 29 14:05:27 2025
comment 1

When git-annex is built with optparse-applicative version 0.14.0.0, it can generate its own zsh completion file. The Makefile installs that, and it seems to work well.

So, I think that the hand-built zsh completions won't need to be maintained much longer!

Comment by joey — Wed Oct 29 14:05:27 2025
Comments on this page are closed.