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

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



Hello Bart,

On 07.04.2015 01:56, Bart Schaefer wrote:
> 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< ---

Unfortunately this doesn't work for me, it leaves me with no git
completion at all. Sorry if it wasn't clear enough, but
`__git_commit_tags` is my own function, the default `_argument` call has
no function at all. Additionally, I had the impression that `source`-ing
completion scripts is not a best practice?

> 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.

That's what I'm doing right now, I've duplicated the function and
replaced/extending the `_argument` call. Works fine, apart from the code
duplication, so I'm probably going to stick to it.

> } 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.

Thanks, I will try that out as soon as the default completer comes with
a function for completing `git commit --fixup`.

Thank you very much and all the best,

  Jochen


Attachment: signature.asc
Description: OpenPGP digital signature



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