* man page completion / regexp
@ 2004-06-06 10:09 Jarkko Maja
2004-06-07 4:55 ` Bart Schaefer
0 siblings, 1 reply; 4+ messages in thread
From: Jarkko Maja @ 2004-06-06 10:09 UTC (permalink / raw)
To: zsh-users
Hi,
I'm have in my zsh-4.0.7 ~/.zshrc the following for
man page completion:
# man page completion
man_glob () {
local a b manp cat
read -cA a
read -lA b
manp=`manpath 2> /dev/null` || manp=`echo
"$MANPATH"`
[[ "$OSTYPE" = *bsd* ]] && cat=,cat
if [[ "$a[2]" = [0-9nlpo](|p) ]] # && [[ -n
"$a[3]" || "${(M)b%
}" = " " ]]
then
reply=( ${^$(echo $manp | sed -e
's/:/
/g')}/{man,sman$cat}$a[2]/$1*(-N.:t) )
else
reply=( ${^$(echo $manp | sed -e
's/:/
/g')}/{man,sman$cat}[0-9nlpo]{,X,m}*/$1*(-N.:t) )
fi
reply=( ${reply%.[^0-9Xmnlpo]*} )
# Uncomment to strip trailing section names
from reply
#reply=( ${reply%.[0-9Xmnlpo]*} )
}
compctl -K man_glob -x 'C[-1,-P]' -m - \
'R[-*l*,;]' -g '*.(man|[0-9Xmnlpo](|[a-z]))'
-- + -f -g '..' man
# Uncomment to accept man page names with trailing
section names, e.g.,
man.1
man () {
local test=${(M)@#*/} # File name probably
contains a slash
if [[ -z "$test" ]] && [[ $# -lt 3 ]]
then
command man
${(M)${${(M)@%.[0-9Xmnlpo]*}#.}#[0-9Xmnlpo]}
${@%.[0-9Xmnlpo]*}
else
command man "$@"
fi
}
This works perfect in Linux/*BSD/Solaris. E.g., man
locale[TAB] gives: locale.1 locale.5 locale.7 etc and
man locale.7 becomes man 7 locale. And man 7
locale[TAB] shows only locale.7. However, with newer
versions of Linux's man-pages package there are also
sections like 0p, 1p, 3p and, e.g., man man.1p becomes
man 1 man. So, to overcome this, I got man 1p man by
this:
command man
${(M)${${(M)@%.[0-9Xmnlpo]*}#.}%%[0-9Xmnlpo](|p)}
${@%.[0-9Xmnlpo]*}
But then I have problem because man
X509_NAME_ENTRY_create_by_NID.3ssl becomes to man l
X509_NAME_ENTRY_create_by_NID and previously it was
correctly man 3 ... Also there man pages in dir
man/man3 like LWP.3pm.
Any hints are welcome, I've pretty much tested
everything I can imagine. If you can get this working,
I'd be delighted to know how to fix this!
Thanks in advance.
__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: man page completion / regexp
2004-06-06 10:09 man page completion / regexp Jarkko Maja
@ 2004-06-07 4:55 ` Bart Schaefer
0 siblings, 0 replies; 4+ messages in thread
From: Bart Schaefer @ 2004-06-07 4:55 UTC (permalink / raw)
To: zsh-users
On Sun, 6 Jun 2004, Jarkko Maja wrote:
> I'm have in my zsh-4.0.7 ~/.zshrc the following for man page completion:
The misplaced line-breaks caused by cut-and-paste combined with your email
client (?) is so bad that I really can't tell what's supposed to be going
on in that function.
However, based on what you say here:
> This works perfect in Linux/*BSD/Solaris. E.g., man locale[TAB] gives:
> locale.1 locale.5 locale.7 etc and man locale.7 becomes man 7 locale.
> [...] However, with newer versions of Linux's man-pages package there
> are also sections like 0p, 1p, 3p and, e.g., man man.1p becomes man 1
> man. So, to overcome this, I got man 1p man by this:
>
> command man
> ${(M)${${(M)@%.[0-9Xmnlpo]*}#.}%%[0-9Xmnlpo](|p)}
> ${@%.[0-9Xmnlpo]*}
>
> But then I have problem because man X509_NAME_ENTRY_create_by_NID.3ssl
> becomes to man l
Your troubles are with ${(M)${${(M)@%.[0-9Xmnlpo]*}#.}%%[0-9Xmnlpo](|p)}
which breaks down as follows:
${(M)@%.[0-9Xmnlpo]*} extracts the extension, including the dot, but
only if it begins with one of the man page section letters.
${${...}#.} removes the leading dot. You might be able to replace
all of this with ${@:e} if you're willing to sacrifice a little accuracy.
${(M)${...}%%[0-9Xmnlpo](|p)} extracts the longest tail of the extension
that matches the man page sectioning scheme.
It should be pretty clear that what you want is not the longest tail of
the extension that matches, which in the case of "3ssl" is "l", but the
longest head, which is "3". So the first thing to try is replacing %%
with ##.
However, this leads to another gotcha, which is that alternatives given
with (|) are tried in left-to-right order until _any_ _one_ matches, NOT
until the _longest_ one matches, even when used with %% or ##. In the
case of (|p), that means that the empty alternative always matches and
hence man.1p becomes 1. If you change it to (p|), you'll get 1p which
is what you want.
(Interestingly, though, when asking for the shortest match with # or %,
the empty alternative in (p|) is correctly chosen regardless of the order,
which suggests there may be a bug in ## and %%.)
So ${(M)${${(M)@%.[0-9Xmnlpo]*}#.}##[0-9Xmnlpo](p|)} is your answer, or
${(M)${@:e}##[0-9Xmnlpo](p|)} if you shorten it as I suggested.
> Also there man pages in dir man/man3 like LWP.3pm.
Which should reduce to 3 rather than 3p, I guess. The only way to deal
with that without resorting to extendedglob patterns is to chop off the
"pm" with ${${...}%pm} before attempting to match "3p". That leaves you
with ${(M)%{(@)${@:e}%pm}##[0-9Xmnlpo](p|)} or similar.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: man page completion / regexp
@ 2004-06-07 8:42 Michael Dettmer
0 siblings, 0 replies; 4+ messages in thread
From: Michael Dettmer @ 2004-06-07 8:42 UTC (permalink / raw)
To: jarkko1982; +Cc: zsh-users
Hi,
looks rather complicated to me
Here's my solution for Solaris only:
(part of .zprofile)
MNPG="'"`echo $MANPATH|awk -F: '{for(i=1;i<=NF;i++)printf("%s/*/*(:t)
",$i)}'`"'"
compctl -g $MNPG man
Michael.
>>> Jarkko Maja <jarkko1982@yahoo.com> 06.06.2004 12:09:44 >>>
Hi,
I'm have in my zsh-4.0.7 ~/.zshrc the following for
man page completion:
# man page completion
man_glob () {
local a b manp cat
read -cA a
read -lA b
manp=`manpath 2> /dev/null` || manp=`echo
"$MANPATH"`
[[ "$OSTYPE" = *bsd* ]] && cat=,cat
if [[ "$a[2]" = [0-9nlpo](|p) ]] # && [[ -n
"$a[3]" || "${(M)b%
}" = " " ]]
then
reply=( ${^$(echo $manp | sed -e
's/:/
/g')}/{man,sman$cat}$a[2]/$1*(-N.:t) )
else
reply=( ${^$(echo $manp | sed -e
's/:/
/g')}/{man,sman$cat}[0-9nlpo]{,X,m}*/$1*(-N.:t) )
fi
reply=( ${reply%.[^0-9Xmnlpo]*} )
# Uncomment to strip trailing section names
from reply
#reply=( ${reply%.[0-9Xmnlpo]*} )
}
compctl -K man_glob -x 'C[-1,-P]' -m - \
'R[-*l*,;]' -g '*.(man|[0-9Xmnlpo](|[a-z]))'
-- + -f -g '..' man
# Uncomment to accept man page names with trailing
section names, e.g.,
man.1
man () {
local test=${(M)@#*/} # File name probably
contains a slash
if [[ -z "$test" ]] && [[ $# -lt 3 ]]
then
command man
${(M)${${(M)@%.[0-9Xmnlpo]*}#.}#[0-9Xmnlpo]}
${@%.[0-9Xmnlpo]*}
else
command man "$@"
fi
}
This works perfect in Linux/*BSD/Solaris. E.g., man
locale[TAB] gives: locale.1 locale.5 locale.7 etc and
man locale.7 becomes man 7 locale. And man 7
locale[TAB] shows only locale.7. However, with newer
versions of Linux's man-pages package there are also
sections like 0p, 1p, 3p and, e.g., man man.1p becomes
man 1 man. So, to overcome this, I got man 1p man by
this:
command man
${(M)${${(M)@%.[0-9Xmnlpo]*}#.}%%[0-9Xmnlpo](|p)}
${@%.[0-9Xmnlpo]*}
But then I have problem because man
X509_NAME_ENTRY_create_by_NID.3ssl becomes to man l
X509_NAME_ENTRY_create_by_NID and previously it was
correctly man 3 ... Also there man pages in dir
man/man3 like LWP.3pm.
Any hints are welcome, I've pretty much tested
everything I can imagine. If you can get this working,
I'd be delighted to know how to fix this!
Thanks in advance.
__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/
^ permalink raw reply [flat|nested] 4+ messages in thread
[parent not found: <s0c446a5.012@fs-prx1.hansemerkur.de>]
* Re: man page completion / regexp
[not found] <s0c446a5.012@fs-prx1.hansemerkur.de>
@ 2004-06-07 19:45 ` Jarkko Maja
0 siblings, 0 replies; 4+ messages in thread
From: Jarkko Maja @ 2004-06-07 19:45 UTC (permalink / raw)
To: zsh-users
Hi Bart,
thanks for your help, now everything works perfectly
again! Below for others who might be interested is
another shot of my config, Yahoo! mail seems to wrap
lines at random.
Thanks!
# man page completion
man_glob () {
local a b manp cat
read -cA a
read -lA b
manp=`manpath 2> /dev/null` || manp=`echo "$MANPATH"`
[[ "$OSTYPE" = *bsd* ]] && cat=,cat
if [[ "$a[2]" = [0-9nlpo](p|) ]] # && [[ -n "$a[3]"
|| "${(M)b% }" = " " ]]
then
reply=( ${^$(echo $manp | sed -e 's/:/
/g')}/{man,sman$cat}$a[2]/$1*(-N.:t) )
else
reply=( ${^$(echo $manp | sed -e 's/:/
/g')}/{man,sman$cat}[0-9nlpo]{,X,m}*/$1*(-N.:t) )
fi
reply=( ${reply%.[^0-9Xmnlpo]*} )
# Uncomment to strip trailing section names from
reply
#reply=( ${reply%.[0-9Xmnlpo]*} )
}
compctl -K man_glob -x 'C[-1,-P]' -m - \
'R[-*l*,;]' -g '*.(man|[0-9Xmnlpo](|[a-z]))' -- + -f
-g '..' man
# Uncomment to accept man page names with trailing
section names, e.g., man.1
man () {
local test=${(M)@#*/} # File name probably contains a
slash
if [[ -z "$test" ]] && [[ $# -lt 3 ]]
then
command man
${(M)${${${(M)@%.[0-9Xmnlpo]*}#.}%pm}##[0-9Xmnlpo](p|)}
${@%.[0-9Xmnlpo]*}
else
command man "$@"
fi
}
__________________________________
Do you Yahoo!?
Friends. Fun. Try the all-new Yahoo! Messenger.
http://messenger.yahoo.com/
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2004-06-07 19:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-06-06 10:09 man page completion / regexp Jarkko Maja
2004-06-07 4:55 ` Bart Schaefer
2004-06-07 8:42 Michael Dettmer
[not found] <s0c446a5.012@fs-prx1.hansemerkur.de>
2004-06-07 19:45 ` Jarkko Maja
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).