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

Re: [PATCH] Completion: Improve _man (3)



On Fri, Jun 15, 2018 at 4:21 PM, dana <dana@xxxxxxx> wrote:
> On 15 Jun 2018, at 09:05, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
>>Thanks for the quick turnaround.  With this patch, `man 3 utf<TAB>`,
>>`man 3per utf<TAB>`, and `man 3perll utf<TAB>` all complete to
>>`... utf8`.  That's correct for the first two but wrong for the last one:
>
> Oops, i confused myself looking at the old one. Fixing that actually improves
> the partial matching a lot in general, thanks. Try this, if you don't mind.
>
> @@ -232,7 +245,23 @@ _man() {
>
>    if [[ $sect = (<->*|[lnopx]) || $sect = *\|* ]]; then
>      sects=( ${(s.|.)sect} )
> -    dirs=( $^_manpath/(sman|man|cat)${^sects}(|.*)/ )
> +
> +    # Most man implementations support partial matching of a page's
> +    # (sub-)section name — e.g., `3per` for `3perl`. The (sub-)section name may
> +    # or may not correspond to the directory name (most systems combine
> +    # sub-sections), but we'll assume that if it starts with a number and we're
> +    # not on Solaris (which doesn't support this feature at all) that we can do
> +    # a match against the leading number. This is irritating if you DO want the
> +    # exact sub-section specified, but unfortunately there's no way to determine
> +    # this programmatically — i guess we could add a style to control it
> +    () for 1 {
> +      if [[ $OSTYPE == solaris* || $1 != <->* ]]; then
> +        dirs+=( $^_manpath/(sman|man|cat)$1(|.*)/ )
> +      else
> +        dirs+=( $^_manpath/(sman|man|cat)${1%%[^0-9]#}*/ )
> +      fi
> +    } $sects
> +

Please don't use () for 1 {} a b c style loops in actual scripts, it
is not guaranteed to work. Instead, use () { for 1 { } } a b c which
is the documented syntax.

-- 
Mikael Magnusson



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