Benabik Alvar (benabik) wrote,
Benabik Alvar
benabik

  • Mood:
  • Music:

OS X Terminal Tip: lsbom completion

Copy the following into ~/.profile in order to get intelligent bash completion for lsbom:

_lsbom () {
    local cur i j temp
    cur=${COMP_WORDS[COMP_CWORD]}

    COMPREPLY=( $( compgen -f -X "!*.bom" -- $cur ) )
    if [ -z "${COMPREPLY[@]}" ]; then
        COMPREPLY=()
        temp=( $( compgen -d -X "!*.pkg" -- $cur ) )
        j=0
        for (( i=0; i < ${#temp[*]}; ++i )); do
            if [ -f "${temp[$i]}/Contents/Archive.bom" ]; then
                COMPREPLY[$((j++))]="${temp[$i]}/Contents/Archive.bom"
            fi  
        done
    fi  
}

complete -F _lsbom -o dirnames lsbom

What is lsbom? It displays the contents of a "Bill of Materials" file. These files are generally inside install packages at PACKAGE_FILE/Contents/Archive.bom. Using lsbom -s PACKAGE_FILE/Contents/Archive.bom will give you a quick list of all the files that package will install.

The completion code above will cause bash to auto-complete (when you use tab) any *.bom files OR a *.pkg/Contents/Archive.bom if it exists. Very useful for me at least, hope others may find it useful.

To test it out try lsbom -s /Library/Receipts/<TAB> in the Terminal

Subscribe
  • Post a new comment

    Error

    default userpic

    Your IP address will be recorded 

    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.
  • 0 comments