zsh-users
 help / color / mirror / code / Atom feed
* completion: lookup argument using descriptions
@ 2021-06-10  9:30 Tomasz Pala
  2021-06-10  9:45 ` Roman Perepelitsa
  0 siblings, 1 reply; 6+ messages in thread
From: Tomasz Pala @ 2021-06-10  9:30 UTC (permalink / raw)
  To: zsh-users

Hello,

sometimes I find myself looking for appropriate option by reading down
all the descriptions of the arguments before going straight to the
documentation to simply /search for some phrase. I wonder: would that be
possible directly from zle? E.g. let me do the flood ping (-f):

$ ping -[tab]
option
-4  -- use IPv4 only
-6  -- use IPv6 only
-A  -- adaptive
-B  -- don't allow ping to change source address
-D  -- print timestamp before each line
-F  -- allocate and set 20-bit flow label
-I  -- specify source interface
-L  -- disable loopback of multicast packets
-M  -- specify path MTU discovery strategy
-N  -- send ICMPv6 node information queries instead of echo request
-O  -- report outstanding ICMP ECHO reply before sending next packet
-Q  -- set Quality of Service-related bits in ICMP datagrams
-R  -- record route
-S  -- set socket sndbuf
-T  -- set special IP timestamp options
-U  -- print full user-to-user latency
-V  -- display version information
-W  -- specify time to wait for a response
-a  -- audible bell for each packet
-b  -- allow pinging a broadcast address
-c  -- specify number of packets to send
-d  -- set SO_DEBUG on the socket
-f  -- flood ping				<- here it is
-h  -- show usage information
-i  -- specify delay between packets
-l  -- send specified number of initial packets as fast as possible
-m  -- specify mark to tag outgoing packets
-n  -- show network addresses as numbers
-p  -- specify pad bytes to fill sent packet with
-q  -- quiet
-r  -- bypass normal routing tables
-s  -- specify packet size
-t  -- set IP Time to Live for outgoing packets
-v  -- verbose output
-w  -- specify timeout after which ping exits


Is there any direct mechanism I could use to search for "flood" in the right
part of the completion? Other than ctrl+a [ / in screen?


regards,
-- 
Tomasz Pala <gotar@pld-linux.org>


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

* Re: completion: lookup argument using descriptions
  2021-06-10  9:30 completion: lookup argument using descriptions Tomasz Pala
@ 2021-06-10  9:45 ` Roman Perepelitsa
  2021-06-10 10:09   ` Mikael Magnusson
  0 siblings, 1 reply; 6+ messages in thread
From: Roman Perepelitsa @ 2021-06-10  9:45 UTC (permalink / raw)
  To: Tomasz Pala; +Cc: Zsh Users

On Thu, Jun 10, 2021 at 11:31 AM Tomasz Pala <gotar@polanet.pl> wrote:
>
> Hello,
>
> sometimes I find myself looking for appropriate option by reading down
> all the descriptions of the arguments before going straight to the
> documentation to simply /search for some phrase. I wonder: would that be
> possible directly from zle?

Try this:

    zmodload zsh/complist
    setopt menucomplete
    zstyle ':completion:*' menu select=0 search

This will allow you to search right away after TAB.

Roman.


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

* Re: completion: lookup argument using descriptions
  2021-06-10  9:45 ` Roman Perepelitsa
@ 2021-06-10 10:09   ` Mikael Magnusson
  2021-06-13 10:06     ` Tomasz Pala
  0 siblings, 1 reply; 6+ messages in thread
From: Mikael Magnusson @ 2021-06-10 10:09 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Tomasz Pala, Zsh Users

On 6/10/21, Roman Perepelitsa <roman.perepelitsa@gmail.com> wrote:
> On Thu, Jun 10, 2021 at 11:31 AM Tomasz Pala <gotar@polanet.pl> wrote:
>>
>> Hello,
>>
>> sometimes I find myself looking for appropriate option by reading down
>> all the descriptions of the arguments before going straight to the
>> documentation to simply /search for some phrase. I wonder: would that be
>> possible directly from zle?
>
> Try this:
>
>     zmodload zsh/complist
>     setopt menucomplete
>     zstyle ':completion:*' menu select=0 search
>
> This will allow you to search right away after TAB.
>
> Roman.

If you only want to do this sometimes (since defaulting to search mode
for all completion is probably extremely annoying), you can bind it to
a separate key;

zle -C menu-select-search menu-complete _generic
zstyle ':completion:menu-select-search:*' menu select search
zstyle ':completion:menu-select-search:*' completer _oldlist _expand _complete
bindkey "^[M"  menu-select-search # alt-shift-m

or if you already have a key bound to start regular menu selection, eg
bindkey "^[m"  menu-select
(this requires no other setup, it's a stock widget)
then you can press ^R to enter the search mode from there, if you also do
bindkey -M menuselect '^R' history-incremental-search-forward
(this is handled specially in menu select mode, and won't actually
invoke history searching.)

-- 
Mikael Magnusson


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

* Re: completion: lookup argument using descriptions
  2021-06-10 10:09   ` Mikael Magnusson
@ 2021-06-13 10:06     ` Tomasz Pala
  2021-06-13 10:43       ` Roman Perepelitsa
  0 siblings, 1 reply; 6+ messages in thread
From: Tomasz Pala @ 2021-06-13 10:06 UTC (permalink / raw)
  To: Mikael Magnusson; +Cc: Roman Perepelitsa, Zsh Users

On Thu, Jun 10, 2021 at 12:09:06 +0200, Mikael Magnusson wrote:

> On 6/10/21, Roman Perepelitsa <roman.perepelitsa@gmail.com> wrote:
>>
>>     zstyle ':completion:*' menu select=0 search
>>
>> This will allow you to search right away after TAB.
>>
>> Roman.
> 
> If you only want to do this sometimes (since defaulting to search mode
> for all completion is probably extremely annoying), you can bind it to
> a separate key;
[...]
> then you can press ^R to enter the search mode from there, if you also do
> bindkey -M menuselect '^R' history-incremental-search-forward
> (this is handled specially in menu select mode, and won't actually
> invoke history searching.)

Thank you so much Roman and Mikael, that was what I needed:)

How do you know about the 'search' option? I don't find it documented
anywhere, namely not in
https://zsh.sourceforge.io/Guide/zshguide06.html#l158

Also, the behaviour of history-incremental-search-forward widget in
menuselect keymap is vaguely documented (actually, misleading):
https://zsh.sourceforge.io/Doc/Release/Zsh-Modules.html#Menu-selection


So now I wonder whether it is possible to highlight the isearch match
from within menuselect. Apparently zle_highlight='(isearch...)' doesn't work,
leaving me with zstyle ':completion:*:options:' list-colors ...

For this however I don't see any way to get the isearch *value* entered - I
see only ISEARCHMATCH_* that could be used by region_highlight(), and
LASTSEARCH. Yet LASTSEARCH also seems to be not updated inside menuselect:

$ o='=(#b)*(-- *($LASTSEARCH)*)=1;31=1;32=1;33'; zstyle -e ':completion:*:options' list-colors 'reply=("'"$o"'")'
$ ctrl+r - network - right-arrow (puts 'network' into $LASTSEARCH)
$ ping -[tab] (or whatever brings menu completion)
[...]
-n  -- show network addresses as numbers	- 'network' highlighted
[...]

$ ping -[enter menu selection] [ctrl-r for history-incremental-search-forward]
isearch: flood

In order to update LASTSEARCH i need to perform search inside ZLE itself
and then hit 'undo', which is a bit awkward.


So the question is: is there any way to update LASTSEARCH when using

bindkey -M menuselect '^R' history-incremental-search-forward

?

-- 
Tomasz Pala <gotar@pld-linux.org>


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

* Re: completion: lookup argument using descriptions
  2021-06-13 10:06     ` Tomasz Pala
@ 2021-06-13 10:43       ` Roman Perepelitsa
  2021-06-16 10:04         ` Tomasz Pala
  0 siblings, 1 reply; 6+ messages in thread
From: Roman Perepelitsa @ 2021-06-13 10:43 UTC (permalink / raw)
  To: Tomasz Pala; +Cc: Mikael Magnusson, Zsh Users

On Sun, Jun 13, 2021 at 12:06 PM Tomasz Pala <gotar@polanet.pl> wrote:
>
> How do you know about the 'search' option?

I don't remember how I discovered it. Now I just know it exists.

For completeness sake, it's also possible (albeit not easy) to display
zsh completions using an external command. For example, in my zsh
setup completions are displayed with fzf. Here's how it looks:
https://asciinema.org/a/419996.

Roman.


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

* Re: completion: lookup argument using descriptions
  2021-06-13 10:43       ` Roman Perepelitsa
@ 2021-06-16 10:04         ` Tomasz Pala
  0 siblings, 0 replies; 6+ messages in thread
From: Tomasz Pala @ 2021-06-16 10:04 UTC (permalink / raw)
  To: Roman Perepelitsa; +Cc: Mikael Magnusson, Zsh Users

On Sun, Jun 13, 2021 at 12:43:46 +0200, Roman Perepelitsa wrote:

>> How do you know about the 'search' option?
> 
> I don't remember how I discovered it. Now I just know it exists.

There's more...

zstyle ':completion:*' menu select=1 interactive

The last one is really interesting, although I experience the same
(1) problem as described and presented here:
https://www.reddit.com/r/zsh/comments/8ur9rl/space_in_interactive_menu_completion/
https://asciinema.org/a/189304
and
(2) blocks tab from going into menu selection (one have to use arrows),
(3) doesn't start again after using arrows,
so I won't use this.

> For completeness sake, it's also possible (albeit not easy) to display
> zsh completions using an external command. For example, in my zsh
> setup completions are displayed with fzf. Here's how it looks:
> https://asciinema.org/a/419996.

Thanks a lot for new ideas:) It took me another 2 days to review
fzf-related projects  and I've ended up  with:

bindkey -M emacs '^f' fzf_completion	(from fzf-tab-completion)
bindkey -M emacs '^R' fzf-history-widget (fzf/shell/key-bindings.zsh)

These 2 seems reasonable and working well when called on purpose:
- fzf_completion to search for descriptions of "-- described" options,
- fzf-history-widget for convenience.

Other fzf completions seem disruptive for me and break my CLI flow,
making the work less smooth and effectively slower than pure zsh.

-- 
Tomasz Pala <gotar@pld-linux.org>


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

end of thread, other threads:[~2021-06-16 10:05 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-10  9:30 completion: lookup argument using descriptions Tomasz Pala
2021-06-10  9:45 ` Roman Perepelitsa
2021-06-10 10:09   ` Mikael Magnusson
2021-06-13 10:06     ` Tomasz Pala
2021-06-13 10:43       ` Roman Perepelitsa
2021-06-16 10:04         ` Tomasz Pala

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