11

I found myself in a situation where I constantly look for parameters of a command in bash. For instance, find -type f -name '*py' -print0. In order to find all of those I need to go through man,info, or --help option which is laborious and time consuming. Is there any way to make this search instant. Ideally, I would love to see something like: find -type --help stating help on type option of find.

Sergey Ivanov
  • 3,719
  • 7
  • 34
  • 59
  • 1
    It would be useful, but I don't think it is possible. Some programs indeed integrate such feature within themselves, such as by "program --help type" to ask help on the "-type" parameter. However maybe it is possible to construct some arcane shell script which would excavate this info from the man pages. – Jubatian Jul 07 '13 at 06:21
  • I don't know about bash, but zsh is fairly easy to write plugins for, so you may have more luck with that. – beatgammit Jul 07 '13 at 06:54

3 Answers3

13

If your man pages open in less you can use / to search over it.

man find

/-type

n, for next search

N for previous search

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Blaz Balon
  • 189
  • 1
  • 3
  • Very nice. Though not as powerful as a direct search. – Sergey Ivanov Jul 07 '13 at 07:46
  • 2
    One way to improve it is to precede the query with double space as in `/ -OPTION` - that way you'll effectively end up right at the definition in most cases, skipping parts where `-OPTION` might be used within a sentence. This is actually something I was looking for. – krzemian Jan 12 '17 at 11:53
1

Here's something I have in my .bashrc

# man search
mans()
{
    if [ $# -ne 2 ]; then
        echo "I need 2 args.  a man page and a search phrase."
        exit 1
    else
        man -Pless "$1" | grep -C10 --group-separator="==============================" -- "$2"
    fi
}

mans find type searches the man page for all occurrences of the phrase "type."

Or: mans find -type (with the dash) if you know the exact option you're looking for.

elcash
  • 401
  • 2
  • 10
1

You can put

function mangrep { man -P less\ -p\ \""${1}"\" ${2}; }

to your .bashrc. Then mangrep pattern page will open the manpage with less and directly search for pattern, as in Blaz Balons answer. So

mangrep " -print" find

gives you the right spot for the -print option of find. And you can still use n/N for forward and backward searching as well as all other features of less.

Community
  • 1
  • 1
gmoktop
  • 131
  • 1
  • 4