git @ Cat's Eye Technologies shelf / master shelf_tabcomplete.sh
master

Tree @master (Download .tar.gz)

shelf_tabcomplete.sh @masterraw · history · blame

# SPDX-FileCopyrightText: Chris Pressey, the original author of this work, has dedicated it to the public domain.
# For more information, please refer to <https://unlicense.org/>
# SPDX-License-Identifier: Unlicense

# tab-completion setup for shelf in bash
# source this file after shelf has been loaded.
# note, I do not claim to entirely know what I'm doing here.

function _shelf_cd_tabcomplete_()
{
    local cmd="${1##*/}"
    local word=${COMP_WORDS[COMP_CWORD]}
    local line=${COMP_LINE}

    local path=`echo "$SHELF_PATH" | sed -e 's/:/ /g'`
    local subdirs=''
    for d in $path; do
        if [ -d $d ]; then
            these=`ls $d`
            subdirs="$subdirs $these"
        fi
    done

    COMPREPLY=($(compgen -W "${subdirs}" "${word}"))
}

complete -F _shelf_cd_tabcomplete_ shelf_cd


function _shelf_which_tabcomplete_()
{
    local cmd="${1##*/}"
    local word=${COMP_WORDS[COMP_CWORD]}
    local line=${COMP_LINE}

    local path=`echo "$SHELF_PATH" | sed -e 's/:/ /g'`
    local files=`ls $SHELF_FARMBASE/bin`

    COMPREPLY=($(compgen -W "${files}" "${word}"))
}

complete -F _shelf_which_tabcomplete_ shelf_which