Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Extend/Modify/Reuse/Augment existing completion functions



On Apr 6,  9:14pm, Jochen Keil wrote:
}
} Can I somehow just add my own completion function for
} `git commit --fixup` without copying over the whole thing?

Something like the following should work:

Create a file named _git and place it in a directory that appears early
enough in your $fpath that your _git will be autoloaded before the one
supplied with zsh.  That file contains

#--- 8< ---
local -a gitpaths
gitpaths=( $^fpath/_git(N) )
source $gitpaths[2] || return

# Now we've loaded _git, override a function therein
__git_commit_tags () {
  commits=("${(@f)$(git log --pretty=format:'%h:%s')}")
  _describe 'commits' commits
}

_git "$@"
#--- 8< ---

If you need to add/replace an argument in one of the embedded _arguments
calls, you'll likely have to duplicate and override the whole function
that makes that particular call; you can do some source-editing tricks
using the $functions parameter from the zsh/parameter module, but it'd
be a bit ugly.


} In addition, I've seen that the dev branch already has completion
} support for `--fixup`. In case I don't like it when it hits the next
} release, is there a way to override just this specific completion?

You can substitute in pretty much anything by using the "completer"
zstyle; just put your completer first in the list, and make sure it
returns nonzero any time it wants the "regular" completers such as
_complete to take over.



Messages sorted by: Reverse Date, Date, Thread, Author