summaryrefslogtreecommitdiff
path: root/package/.sdb-completion.bash
blob: d58fc0b3e63bac535a3531291de64d3491dea64c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
_sdb()
{
    #sdb path is defined in PATH environment variable
    COMPREPLY=()

    SDB_PATH=$(eval eval echo \$\{COMP_WORDS\[0\]\})

    if [ ! -f ${SDB_PATH} ];
    then
        return 0;
    fi

#    cur="${COMP_WORDS[COMP_CWORD]}"
    ARGS="autocomplete,${COMP_CWORD}"

    local IFS=$','
    for ((i=1; i < $((${COMP_CWORD} + 1)) ; i++))
    do
        #processing for echo options
        if [ "${COMP_WORDS[i]}" == "-e" ]; then
            convertedarg=-e
        elif [ "${COMP_WORDS[i]}" == "-n" ]; then
            convertedarg=-n
        else
            convertedarg=$(eval eval echo \$\{COMP_WORDS\[i\]\})
        fi
        ARGS="${ARGS}${IFS}${convertedarg}"
    done

    next=($("${SDB_PATH}" ${ARGS}))
    local IFS=$'\n'
    COMPREPLY=(${next})
#    COMPREPLY=($(compgen -W "${next}" -- ${cur}))

    return 0
}

complete -o filenames -F _sdb sdb