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

Re: show completion description in single line



Hi Brat Schaefer,

I can not express my gratitude with words. Thank you very much for showing us how it is done.

I have modified the __git_extract_aliases in this case. solarizedalias came up with this solution (https://www.reddit.com/r/zsh/comments/jdlavm/show_completion_description_in_single_line/g9b1lrk?utm_source=share&utm_medium=web2x&context=3).

So, the resulting function is:

(( $+functions[__git_extract_aliases] )) ||
__git_extract_aliases () {
    local -a tmp match mbegin mend
    tmp=(${${(0)"$(_call_program aliases "git config -z --get-regexp '^alias.'")"}#alias.})
    if (( ${#tmp} > 0 )); then
        aliases=(${^tmp/$'\n'/:alias for \'}\')
        aliases=( ${(@)aliases//(#b)alias for \'(*)\'/alias for "'${match[1]//$'\n'/ }'"} )
    else
        aliases=()
    fi
}

Best Regards,

Ahmad Ismail



On Mon, Oct 19, 2020 at 3:59 AM Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx> wrote:
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.

__git_extract_aliases

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