ZSH completion for git-annex

Software git-annex, zsh

I love git-annex. It works extremely well, its documentation is excellent, and Joey Hess, its main developper, is amazingly reactive when you tell him about a bug or ask him any question about this software. I’m currently using git-annex to manage almost 1 TB of data, spread over my laptop, my NAS, a few external hard drives, and my hubiC account. (Yes, git-annex is also designed to be able to use many different storage backends, and it’s really easy to write new ones, which I did for hubiC; more on that later…)

The biggest issue annoyance with git-annex is the lack of completion when using ZSH. The completion for git is amazing, so it’s quite weird to have nothing for git-annex.

But as often with free software, someone has already started scratching that itch: I found a basic completion function for git-annex!

It’s for an old version of git-annex, but I’ve been able to update it to the latest version of git-annex:

The updated code is available on https://github.com/Schnouki/git-annex-zsh-completion. To install that, just copy the _git-annex file to some directory in your $fpath (I use $HOME/.config/zsh/completion), and run autoload -U path/to/_git-annex. You will also need to have Python 3 somewhere in your $PATH as python3 (tested with 3.4, should work with 3.2+).

Many, many thanks to the awesome people who started this completion function: Frank Terbeck and Valentin Haenel. And to Joey for his amazing work on git-annex.

Comments

Join the conversation by sending an email. Your comment will be added here and to the public inbox after moderation.

ft

Nice to see someone picking it up to bring it up to speed with current git-annex behaviour.

BTW, you don’t need to manually mark the function file for autoloading if the directory you keep it in is a member of $fpath by the time you call ‘compinit’. So add $HOME/.config/zsh/completion to $fpath you call compinit and you can drop the autoload call.

Finally, if you think the function is good enough for inclusion in zsh, then you might consider submitting it to zsh’s development team. Git-annex would then enjoy context sensitive completion out of the box for zsh users.

Regards, Frank

ft

That should be “before you call compinit”.

Schnouki

Frank, thanks for this! :)

I’d love for this function to be included in zsh, but IMO it’s too soon: there are still some details to review for arguments (I think too many args are proposed for some commands), the completion for add / drop / get / … is still lacking, and there are other things to improve first.

And most important, I’m not sure the zsh devs would accept a completion function that depends on Python… but I haven’t found any easy way to parse JSON directly from zsh :/

ft

No rush! :)

When I first read “Depends on Python”, I was also like “Wat.” - But then I skimmed through the code and saw that it was about parsing JSON, which is legitimate, I guess. Directly mapping JSON to zsh datastructures is probably hard anyway, since you can’t have lists of lists or maps of lists etc. natively in zsh.

I’d say, if it doesn’t fail when python is not available, upstream inclusion shouldn’t be a problem. There is one or the other completion, that uses Perl here and there as well. You should just ask on the zsh-workers mailing list once you’re happy with the code.

Regards, Frank