Refer to can-i-get-individual-man-pages-for-the-bash-builtin-commands:
bashman () { man bash | less -p "^ $1 "; }
This function will jump to the desired bash manual parameter section directly.
I want to make it accept any Manual Name and Manual Parameter on the fly, so i change this function to:
function superman () {
man "$1" | less -p "^[ ]+[-]*$2[ ]"
}
It works perfectly with:
$ superman bash type
And jump to the desired man page section:
But it doesn't work in section ending with newline. I need change it to:
function superman () {
man "$1" | less -p "^[ ]+[-]*$2$"
}
Then run $ superman gcc Wall
will able jump to Wall
parameter:
How to combine [ ]
and $
to be [ ] OR $
? i.e. endswith at "atleast one space" OR "newline".
I tried $ man gcc | less -p "^[ ]+[-]*Wall[ |$]"
but it doesn't works.
Please note that i accept for this undesired jump, which is endswith [ ]
but not really a beginning of section, because i believe it's unsolvable if regex is [ ]
OR $
:
[Thanks for answers]
I want to share my final form here:
function superman () {
if [[ "$1" == "-I" || "$1" == "-i" ]]; then
man "$2" | less -I -p "^[ ]+-*$3( |=|,|$|\[)"
else
man "$1" | less -p "^[ ]+-*$2( |=|,|$|\[)"
fi
}
This will work if i run superman -i gcc wl
which means case-insensitive to jump into -Wl,option
section. -Wl,option
from gcc
require ,
. scaletempo
from mplayer
require [
, and scale
from mplayer
require =
I wrote for info
version too:
function superinfo () {
if [[ "$1" == "-I" || "$1" == "-i" ]]; then
info "$2" | less -I -p "^ *‘*'*-*\** *$3’*( |=|,|$|\[|:|')"
else
info "$1" | less -p "^ *‘*'*-*\** *$2’*( |=|,|$|\[|:|')"
fi
}
Tested with superinfo gcc _HPPA
, superinfo -i gcc werror
, superinfo -i gcc wl
, superinfo -i mplayer scaletempo
, superinfo -i mplayer stats
, superinfo -i ls -f
, and superinfo -i bash -a
(with minus sign make big difference here). Unicode's LEFT SINGLE QUOTATION MARK ’
used by -f
of ls
.
b () { LESS="+/^ *$*" man bash;}
so I can do, for instance,b history expansion
. – Wildcard Oct 22 '16 at 18:35info
where the data is properly indexed. Likeinfo bash type
. – Stéphane Chazelas Oct 22 '16 at 19:38info
version too. – 林果皞 Oct 22 '16 at 20:48