zsh-users
 help / color / mirror / code / Atom feed
* show completion description in single line
@ 2020-10-18 18:28 Ahmad Ismail
  2020-10-18 21:59 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Ahmad Ismail @ 2020-10-18 18:28 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 710 bytes --]

Hi All,

I have few multiline aliases for git. The suggestion looks like the
following:
[image: r/zsh - show completion description in single line]
<https://preview.redd.it/u7i8t5pe9wt51.png?width=1920&format=png&auto=webp&s=6335ca5e6027cab470f5a56b2979ca7c4055b4ed>

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

I think the function is:

(( $+functions[__git_aliases] )) ||

__git_aliases () {

local -a aliases

__git_extract_aliases

_describe -t aliases alias aliases $*

}

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

*Thanks and Best Regards,Ahmad Ismail*

[-- Attachment #2: Type: text/html, Size: 3018 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: show completion description in single line
  2020-10-18 18:28 show completion description in single line Ahmad Ismail
@ 2020-10-18 21:59 ` Bart Schaefer
  2020-10-19 10:24   ` Ahmad Ismail
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2020-10-18 21:59 UTC (permalink / raw)
  To: Ahmad Ismail; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 1902 bytes --]

On Sun, Oct 18, 2020 at 11:28 AM Ahmad Ismail <ismail783@gmail.com> 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.

[-- Attachment #2: Type: text/html, Size: 2638 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: show completion description in single line
  2020-10-18 21:59 ` Bart Schaefer
@ 2020-10-19 10:24   ` Ahmad Ismail
  0 siblings, 0 replies; 3+ messages in thread
From: Ahmad Ismail @ 2020-10-19 10:24 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 2885 bytes --]

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@brasslantern.com>
wrote:

> On Sun, Oct 18, 2020 at 11:28 AM Ahmad Ismail <ismail783@gmail.com> 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.
>

[-- Attachment #2: Type: text/html, Size: 5032 bytes --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-10-19 10:25 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-10-18 18:28 show completion description in single line Ahmad Ismail
2020-10-18 21:59 ` Bart Schaefer
2020-10-19 10:24   ` Ahmad Ismail

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).