MacOS – Bash Autocomplete Script with El Capitan

bashmacosterminal

About a week ago, I added the following to the end of my .bash_profile script so set up tab completion for man pages:

function _man_pages()
{
    local cur opts prev
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"      #Get the current word
    prev="${COMP_WORDS[COMP_CWORD - 1]}" #Get the previous word
    opts=""
    if [ "$prev" = "man" ];
    then
        #We didn't use a section number
        #This lovely regex converts from the file path to the name of the page
        opts=$(find -E "/usr/share/man" -regex ".*/man[1-9n]/(${cur}.*)\.[1-9n].*$" | sed -E 's/^.*\/(.*)\.[1-9n].*$/\1/')
    else 
        #We entered a section number
        opts=$(find -E "/usr/share/man" -regex ".*/man${prev}/(${cur}.*)\.${prev}.*$" | sed -E "s/^.*\/(.*)\.${prev}.*$/\1/")
    fi

    COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
    return 0
}

complete -F _man_pages man

However, when I updated to El Capitan this morning, it stopped working. I've successfully run the regex portion of the script in my terminal itself, so I'm confident that they are still correct. Can anyone explain why this is happening, and/or how to fix it?

Thanks!

UPDATE: After doing a little more digging, I've discovered that it still works for most man pages, just not man 2 or man 3. After looking in the correct folder it was before, the folders man2 and man3 are gone. I'm still able to do "man pthread_create" and get results, so those folders must have gone somewhere. I'll be back when I know more.

Best Answer

After some more digging, I found that I can do "man -W" to get a list of folders that man checks when looking for the pages themselves, including the one where pthread_create is.

P.S. It looks like it's in the Xcode app folder now.