5

I have a bunch of tools that pass all arguments to an internal invocation of e.g. "git log". A trivial example might look like:

#!/usr/bin/env zsh
git log --since='1 year ago' "$@"

I know that I can have completion aliases by doing e.g.:

compdef myscript=grep

However, it's not clear how to do this for subcommands like git log. Is there a way to do this?

Zach Riggle
  • 2,975
  • 19
  • 26
  • 1
    Does this answer your question? [How to add custom git command to zsh completion?](https://stackoverflow.com/questions/38725102/how-to-add-custom-git-command-to-zsh-completion) – phd Mar 30 '20 at 11:15
  • 1
    https://stackoverflow.com/search?q=%5Bzsh%5D+git+subcommand+completion – phd Mar 30 '20 at 11:16

1 Answers1

-1

There is a solution which will work with aliases, but not with functions or scripts. In your case, with git log, it is enough.

  1. Create an alias.
    mygitlog="git log --since='1 year ago'"

  2. Enable compinit for zsh completion in your .zshrc.
    autoload -Uz compinit && compinit

  3. Disable completealiases option, which is preventing aliases from being internally substituted before completion is attempted.
    unset completealiases

After typing mygitlog and pressing Tab twice in Git repository, zsh will suggest you commits and tags that were made in the last year.