Seeing all pages available in section 9 on FreeBSD

Posted on

When I am working with a kernel module in FreeBSD, there are times that I want to see all functions available in man 9. I know that apropos is out there but I sometimes don't know the keyword.

Because of this, I decided to write a simple zsh script to list all available pages in a section, not only in section 9.

function ls_man() {
    if [[ $# -ne 1 ]]; then
        echo "Number of argument must be 1" >&2
        echo "Usage: ls_man [1-9]" >&2
        return 1
    fi

    if [[ $1 == [1-9] ]]; then
        ls /usr/share/man/man$1 | awk '{ split($1, name, ".") } { print name[1] }'
        return 0
    else
        echo "Wrong argument" >&2
        echo "Usage: ls_man [1-9]" >&2
        return 1
    fi
}