# Bash/ZSH completion for t2edit

_t2edit() {
    #compdef t2edit
    local opts=()
    local olddir=`pwd`
    cd "$T2HOME"
    for i in */src/*.[ch]; do
        local b=$(dirname "$i")
        b=$(dirname "$b") # plugin name
        if [ "$b" != "t2PSkel" ]; then
            opts+=("$i")
        fi
    done
    if type compdef &> /dev/null; then
        compadd "${opts[@]}"
    else
        local cur="${COMP_WORDS[COMP_CWORD]}"
        COMPREPLY=($(compgen -W "${opts[*]}" -- "$cur"))
    fi
    cd "$olddir"
}

if type compdef &> /dev/null; then
    compdef _t2edit t2edit
else
    complete -F _t2edit t2edit
fi
