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

Re: show completion description in single line

On Sun, Oct 18, 2020 at 11:28 AM Ahmad Ismail <ismail783@xxxxxxxxx> wrote:

[...]  multiline descriptions are draining my cognitive resources. Is there any way I can trim the description to single line.


However, I am not sure how to do it actually. Being said that, a zstyle solution will be much better for me.

In the interests of "teach a man to fish" ...

If you look at the source of __git_extract_aliases you will see that it does this:

tmp=(${${(0)"$(_call_program aliases "git config -z --get-regexp '^alias.'")"}#alias.})

What you are seeing in the descriptions is thus the output from that "git config" command.  Your goal is to replace that with something that produces less verbose results.

You've already figured out that _call_program looks up the "command" style, so you need to find the right context to pass.  This is where ^X? (the _complete_help binding) comes in handy.  If you type ^X? (ctrl-x questionmark) instead of tab, the completion system will dump a file in /tmp with the full set of instructions that were executed in order to generate the completion matches.  You can then look through that file for the _call_program run and find the context it used.

(This is what I did to find "tree-files" in the other thread, except in that case the $(_call_program ...) had stderr directed to /dev/null, so I had to first remove that redirect.)

As a shortcut ... you can see from the _call_program arguments that the tag is "aliases", so you can construct a wildcard match:

zstyle ':completion::complete:git*:*:aliases' command '...'

Replace "..." with whatever variation of "git config" you need to produce your desired abbreviated results.  If the wildcards unexpectedly match something you didn't intend, then you can dig deeper to find a more specific context.

Note I didn't test the above in any way, so details may need adjustment.

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