#!/bin/bash
# Copying and distribution of this file, with or without modification,
# are permitted in any medium without royalty provided the copyright
# notice and this notice are preserved.
# This file is offered as-is, without any warranty.

SUBCOMMANDS="mkfs mount umount show open run create assign delete \
rename move copy state backup service \
--help --version"

SETOPS=": u: % i: d:"

SYS_DIR=/etc/vitis

COMPREPLY=()


# Receives a sequence of elements and one value (last argument) for comparison,
# prints TRUE if the value is found, else FALSE
Can_Find() {
    local ELEM="${@:$#}"
    for ARG in "${@:1:$#-1}"; do
        if [[ "$ELEM" == "$ARG" ]]; then
            echo TRUE
            return
        fi
    done
    unset ELEM
    unset ARG
    echo FALSE
}


# create VTS_PATH variable
Define_Mount_Path() {
    VTS_PATH="${VTS_MP:-}"
    if [[ ! -d "${SYS_DIR}" ]]; then
        return
    fi
    if [[ -z "$VTS_PATH" ]]; then
        local TOP_DEVICE=$(stat -c%d "${SYS_DIR}")
        for VITIS_MNT in "${SYS_DIR}"/*-vitis; do
            if [[ -e "$VITIS_MNT" ]]; then
                if [[ $(stat -L -c%d "${VITIS_MNT}") != "${TOP_DEVICE}" ]]; then
                    VTS_PATH="${VITIS_MNT}"
                    break
                fi
            fi
        done
    fi
}


Complete_Category() {
    if [[ -z "$VTS_PATH" ]]; then
        return
    fi
    pushd "${VTS_PATH}" &>/dev/null || return 1
    _init_completion -s
    _filedir -d
    popd &>/dev/null

    declare -a _COMPREPLY
    for ITEM in "${COMPREPLY[@]}"; do
        _COMPREPLY+=( "${ITEM}/" )
    done
    compopt -o nospace
    COMPREPLY=( "${_COMPREPLY[@]}" )
    unset _COMPREPLY
    unset _ITEM
}


Complete_Vitis_Path() {
    if [[ -z "$VTS_PATH" ]]; then
        return
    fi
    pushd "${VTS_PATH}" &>/dev/null || return 1
    _init_completion -s
    _filedir
    declare -a _COMPREPLY
    for ITEM in "${COMPREPLY[@]}"; do
        # append a slash if directory
        if [[ -d "$ITEM" ]]; then
            _COMPREPLY+=("${ITEM}/")
            compopt -o nospace
        else
            _COMPREPLY+=("${ITEM}")
        fi
    done
    COMPREPLY=( "${_COMPREPLY[@]}" )
    unset _COMPREPLY
    unset ITEM
    popd &>/dev/null
}


Complete_Relation_By_File() {
    local RS_DIR="${1}\\rs"
    if [[ ! -e "${RS_DIR}" ]]; then
        return
    fi
    pushd "${RS_DIR}" &>/dev/null || return 1
    _init_completion -s
    _filedir
    declare -a _COMPREPLY
    for ITEM in "${COMPREPLY[@]}"; do
        _COMPREPLY+=("${ITEM}")
    done
    COMPREPLY=( "${_COMPREPLY[@]}" )
    unset _COMPREPLY
    unset ITEM
    popd &>/dev/null
}


Complete_Apps() {
    pushd /usr/bin/ &>/dev/null || return 1
    _init_completion -s
    _filedir
    popd &>/dev/null
}


Complete_Path_After_Opt() {
    LAST_OPT="$1"
    case "$LAST_OPT" in
    -c)
        Complete_Category
        ;;
    -f)
        _init_completion -s
        _filedir
        ;;
    -d)
        _init_completion -s
        _filedir
        ;;
    -v)
        Complete_Vitis_Path
        ;;
    -m)
        Complete_Vitis_Path
        ;;
    -e)
        if [[ "${PREV}" == "-e" ]]; then
            Complete_Category
            compopt -o nosort
            COMPREPLY+=( $(compgen -W "[" -- ${CURR}) )
        elif [[ $(Can_Find ${SETOPS} "[" "${PREV}") == TRUE ]]; then
            Complete_Category
            compopt -o nosort
            COMPREPLY+=( $(compgen -W "[" -- ${CURR}) )
        else
            Regular_Completion "${SETOPS} ]"
        fi
        ;;
    -i)
        Regular_Completion "http:// https:// ftp://"
        ;;
    esac
}


Regular_Completion() {
    local LIST="$1"
    COMPREPLY=( $(compgen -W "${LIST}" -- ${CURR}) )
}


Complete_Cmd_Show() {
    SUBCOMMANDS_SHOW="-e -c -v --by-relations"
    OPTIONS_SHOW="--categories --details --relations --relation-details \
    --full-details \
    --tags --xattrs --json --open --run -n -r --reverse \
    --sort=extension --sort=name --sort=size --sort=time \
    --sort=atime --sort=mix \
    --dialog -D --use-canon-name --as-dir"
    OPTIONS_SHOW_V="--categories --details --relations --relation-details \
    --full-details \
    --tags --xattrs --json --open --run --use-canon-name"
    OPTIONS_SHOW_BR="$OPTIONS_SHOW --name -R --direction -W --target -B"

    if [[ ${COMP_CWORD} -eq 2 ]]; then
        Regular_Completion "${SUBCOMMANDS_SHOW}"
        return
    fi
    local SUBCMD="${COMP_WORDS[2]}"
    if [[ $(Can_Find ${SUBCOMMANDS_SHOW} "${PREV}") == FALSE && \
        ( "${PREV}" == -* || "${CURR}" == -* ) ]]
    then  # complete flags only
        if [[ "${SUBCMD}" == "-v" ]]; then
            Regular_Completion "${OPTIONS_SHOW_V}"
        elif [[ "${SUBCMD}" == "--by-relations" ]]; then
            Regular_Completion "${OPTIONS_SHOW_BR}"
        else  # "-c", "-e"
            Regular_Completion "${OPTIONS_SHOW}"
        fi
    elif [[ $(Can_Find ${SUBCOMMANDS_SHOW} "${SUBCMD}") == TRUE ]]; then
        if [[ "${SUBCMD}" == "--by-relations" ]]; then
            if [[ "${PREV}" == "--by-relations" ]]; then
                Regular_Completion "${OPTIONS_SHOW_BR}"
            elif [[ "${CURR}" == -* ]]; then
                Regular_Completion "${OPTIONS_SHOW_BR}"
            elif [[ "${CURR}" == "-W" || "${CURR}" == "--direction" ]]; then
                Regular_Completion ": :- -"
            elif [[ "${CURR}" == "-R" || "${CURR}" == "--name" ]]; then
                Regular_Completion ""
            elif [[ "${CURR}" == "-B" || "${CURR}" == "--target" ]]; then
                Complete_Vitis_Path
            fi
        else
            Complete_Path_After_Opt "${SUBCMD}"
        fi
    fi
}


Complete_Cmd_Open() {
    SUBCOMMANDS_OPEN="-e -c -v"
    OPTIONS_OPEN="-n -r --reverse \
    --sort=extension --sort=name --sort=size \
    --sort=time --sort=atime --sort=mix \
    --app --show -t"
    OPTIONS_OPEN_V="--show --app -t"

    if [[ ${COMP_CWORD} -eq 2 ]]; then
        Regular_Completion "${SUBCOMMANDS_OPEN}"
        return
    fi
    local SUBCMD="${COMP_WORDS[2]}"
    if [[ "${PREV}" == "--app" ]]; then
        Complete_Apps
    elif [[ $(Can_Find ${SUBCOMMANDS_OPEN} "${PREV}") == FALSE && \
        ( "${PREV}" == -* || "${CURR}" == -* ) ]]
    then  # complete options only
        if [[ "${SUBCMD}" == "-v" ]]; then
            Regular_Completion "${OPTIONS_OPEN_V}"
        else
            Regular_Completion "${OPTIONS_OPEN}"
        fi
    elif [[ $(Can_Find ${SUBCOMMANDS_OPEN} "${SUBCMD}") == TRUE ]]; then
        Complete_Path_After_Opt "${SUBCMD}"
    fi
}


Complete_Cmd_Run() {
    SUBCOMMANDS_RUN="-e -v"
    OPTIONS_RUN="-n -r --reverse \
    --sort=extension --sort=name --sort=size --sort=time --sort=atime \
    --sort=mix \
    --show"
    OPTIONS_RUN_V="--show"

    if [[ ${COMP_CWORD} -eq 2 ]]; then
        Regular_Completion "${SUBCOMMANDS_RUN}"
        return
    fi
    local SUBCMD="${COMP_WORDS[2]}"
    if [[ $(Can_Find ${SUBCOMMANDS_RUN} "${PREV}") == FALSE && \
        ( "${PREV}" == -* || "${CURR}" == -* ) ]]
    then  # complete flags only
        if [[ "${SUBCMD}" == "-v" ]]; then
            Regular_Completion "${OPTIONS_RUN_V}"
        else
            Regular_Completion "${OPTIONS_RUN}"
        fi
    elif [[ $(Can_Find ${SUBCOMMANDS_RUN} "${SUBCMD}") == TRUE ]]; then
        Complete_Path_After_Opt "${SUBCMD}"
    fi
}


Complete_Cmd_Create() {
    SUBCOMMANDS_CREATE="-c -v -r -l"
    FLAGS_CREATE_V="--allow-same-names -S --note -N -F -r -t -E --edit"
    FLAGS_CREATE_VF="-s -e -b"
    FLAGS_CREATE_C="--note -N -r"
    FLAGS_CREATE_L="--allow-same-names -S"

    local O1=""
    local O2=""
    local LAST_OPT=""
    local LAST_OPT_INDEX=-1
    for (( index=1; index<${COMP_CWORD}; index++ )); do
        if [[ -n "$O1" && -n "$O2" ]]; then
            break
        fi
        local ARG=${COMP_WORDS[$index]}
        if [[ $ARG == -* ]]; then
            [[ -z "$O1" ]] && O1="$ARG" || O2="$ARG"
            LAST_OPT="${ARG}"
            LAST_OPT_INDEX=index
        fi
    done
    if [[ "${CURR}" == -* && "${LAST_OPT}" == "-c" ]]; then
        Regular_Completion "${FLAGS_CREATE_C}"
    elif [[ "${CURR}" == -* && "${LAST_OPT}" == "-v" ]]; then
        Regular_Completion "${FLAGS_CREATE_V}"
    elif [[ "${O1}" == "-v" && "${O2}" == "-F" ]]; then
        if [[ "${PREV}" != -* && "${CURR}" == -* ]]; then
            Regular_Completion "${FLAGS_CREATE_VF}"
        else
            if [[ "${PREV}" == "-b" ]]; then
                local B="by-time by-line-and-column by-phrase by-page"
                Regular_Completion "$B"
            fi
        fi
    elif [[ "${LAST_OPT}" == "" ]]; then
        Regular_Completion "${SUBCOMMANDS_CREATE}"
    elif [[ "${LAST_OPT}" == "-v" ]]; then
        Complete_Vitis_Path
    elif [[ "${LAST_OPT}" == "-c" ]]; then
        Complete_Category
    elif [[ "${LAST_OPT}" == "-e" ]]; then
        Complete_Path_After_Opt "-e"
    elif [[ "${LAST_OPT}" == '-r' ]]; then
        # vitis create -r <name> <file1> <direction> <file2>
        if [[ "$O1" == '-r' && -z "$O2" ]]; then
            if [[ ${COMP_CWORD} -eq 4 || ${COMP_CWORD} -eq 6 ]]; then
                Complete_Vitis_Path
            elif [[ ${COMP_CWORD} -eq 5 ]]; then
                COMPREPLY=( ":" "=" )
            elif [[ ${COMP_CWORD} -eq 3 ]]; then
                COMPREPLY=()
            fi
        fi
        # vitis create -<key> ... -r <name> <direction> <file_to_bind>
        if [[ "$O2" == '-r' ]]; then
            if [[ "$PREV" == '-r' ]]; then
                COMPREPLY=()
            elif [[ "$PREPREV" == '-r' ]]; then
                COMPREPLY=( ":" "=" )
            elif [[ "$PREPREPREV" == '-r' ]]; then
                Complete_Vitis_Path
            fi
        fi
    elif [[ "${PREV}" == '-l' ]]; then
        Complete_Vitis_Path
    elif [[ "${PREPREV}" == '-l' ]]; then
        Regular_Completion "-p --target-path"
    elif [[ "${PREV}" == '-p' || "${PREV}" == '--target-path' ]]; then
        Complete_Vitis_Path
    elif [[ "${PREPREV}" == '-p' || "${PREPREV}" == '--target-path' ]]; then
        Regular_Completion "${FLAGS_CREATE_L}"
    fi
    unset O1
    unset O2
    unset LAST_OPT
    unset LAST_OPT_INDEX
}


Complete_Cmd_Assign() {
    SUBCOMMANDS_ASSIGN="-f -d -v -e -i -c -n"
    FLAGS_ASSIGN_REG="--allow-same-names -S --create-categories -M --yes --no"
    FLAGS_ASSIGN_NAME="--all -A --allow-same-names -S --update-canon-name -C"
    FLAGS_ASSIGN_MOVE="--allow-same-names -S"
    FLAGS_ASSIGN_I="--create-categories -M --yes --no --allow-same-names -S"
    FLAGS_ASSIGN_I+=" --save-page"
    FLAGS_ASSIGN_D="--create-categories -M --yes --no"

    local O1=""
    local O2=""
    local LAST_OPT=""
    local LAST_OPT_INDEX=-1
    for (( INDEX=1; INDEX<${COMP_CWORD}; INDEX++ )); do
        for OPT in -f -d -v -e -i -c -n -m; do
            if [[ ${COMP_WORDS[$INDEX]} == $OPT ]]; then
                [[ -z "$O1" ]] && O1="$OPT" || O2="$OPT"
                LAST_OPT="$OPT"
                LAST_OPT_INDEX=$INDEX
            fi
        done
    done

    # special case for "vitis assign -d"
    if [[ $COMP_CWORD -ge 3 && ${COMP_WORDS[2]} == "-d" ]]; then
        local CW=$COMP_CWORD
        if [[ $CW -eq 4 ]]; then
            Regular_Completion "-n"
        elif [[ $CW -eq 6 ]]; then
            Regular_Completion "-c"
        elif [[ $CW -ge 8 ]]; then
            if [[ "$CURR" == -* || "$PREV" == -* ]]; then
                Regular_Completion "$FLAGS_ASSIGN_D"
            else
                Complete_Path_After_Opt "$LAST_OPT"
            fi
        else
            Complete_Path_After_Opt "$LAST_OPT"
        fi
        return
    fi

    if [[ -z "$LAST_OPT" ]]; then
        Regular_Completion "${SUBCOMMANDS_ASSIGN}"
    elif [[ -z "$O2" ]]; then
        if [[ "$CURR" != -* ]]; then
            if [[ "$LAST_OPT" == "-n" ]]; then
                :  # COMPREPLY cannot be defined
            else
                Complete_Path_After_Opt "$LAST_OPT"
            fi
        else
            case "$O1" in
                -c) Regular_Completion "-f -v -e -i"          ;;
                -v) Regular_Completion "-c -n -m --save-page" ;;
                -n) Regular_Completion "-v"                   ;;
                *)  Regular_Completion "-c"                   ;;
            esac
        fi
    elif [[ -n "$O1" && -n "$O2" ]]; then
        L=$LAST_OPT_INDEX
        if [[ "${CURR}" == -* ]]; then
            if [[ "$O1" == '-v' && "$O2" == '-n' ]]; then
                Regular_Completion "${FLAGS_ASSIGN_NAME}"
            elif [[ "$O1" == '-n' && "$O2" == '-v' ]]; then  # ditto
                Regular_Completion "${FLAGS_ASSIGN_NAME}"
            elif [[ "$O1" == '-v' && "$O2" == '-m' ]]; then
                Regular_Completion "${FLAGS_ASSIGN_MOVE}"
            elif [[ "$O1" == '-m' && "$O2" == '-v' ]]; then
                Regular_Completion "${FLAGS_ASSIGN_MOVE}"
            elif [[ "$O1" == '-i' && "$O2" == '-c' ]]; then
                Regular_Completion "${FLAGS_ASSIGN_I}"
            elif [[ "$O1" == '-c' && "$O2" == '-i' ]]; then
                Regular_Completion "${FLAGS_ASSIGN_I}"
            else
                if [[ "$O1" == '-f' || "$O2" == '-f' ]]; then
                    Regular_Completion "${FLAGS_ASSIGN_REG} --verbose -V"
                else
                    Regular_Completion "${FLAGS_ASSIGN_REG}"
                fi
            fi
        # like 'vitis assign -v C1/file1 -c C2 -S ..." (-S is PREV)
        elif [[ "${PREV}" == -* && $(expr ${COMP_CWORD}-3) -ge $L ]]; then
            COMPREPLY=( $(compgen -W "${FLAGS}" -- ${CURR}) )
        # vitis assign -v ... -n ...
        elif [[ "$O2" == "-n" && "$PREV" == "-n" ]]; then
            PROPOSED_NAME="$(basename "${PREPREV}")"
            if [[ "$PROPOSED_NAME" == "$CURR"* ]]; then
                COMPREPLY=("$PROPOSED_NAME")
            elif [[ \""$PROPOSED_NAME" == "$CURR"* ]]; then
                PROPOSED_NAME=$(echo $(eval echo "$PROPOSED_NAME"))
                COMPREPLY=("$PROPOSED_NAME")
            else
                COMPREPLY=()
            fi
        else
            Complete_Path_After_Opt "$LAST_OPT"
        fi
    fi
}


Complete_Cmd_Rename() {
    if [[ "${COMP_CWORD}" -eq 2 ]]; then
        Complete_Vitis_Path
    elif [[ "${COMP_CWORD}" -eq 3 ]]; then
        PROPOSED_NAME="$(basename "${PREV}")"
        if [[ "$PROPOSED_NAME" == "$CURR"* ]]; then
            COMPREPLY=("$PROPOSED_NAME")
        elif [[ \""$PROPOSED_NAME" == "$CURR"* ]]; then
            PROPOSED_NAME=$(echo $(eval echo "$PROPOSED_NAME"))
            COMPREPLY=("$PROPOSED_NAME")
        else
            COMPREPLY=()
        fi
    else
        Regular_Completion "${FLAGS_ASSIGN_NAME}"
    fi
}


Complete_Cmd_Move() {
    if [[ "${COMP_CWORD}" -eq 2 || "${COMP_CWORD}" -eq 3 ]]; then
        Complete_Vitis_Path
    else
        Regular_Completion "${FLAGS_ASSIGN_MOVE}"
    fi
}


Complete_Cmd_Copy() {
    if [[ "${COMP_CWORD}" -eq 2 ]]; then
        Regular_Completion "-v"
    elif [[ "${COMP_CWORD}" -eq 3 ]]; then
        Complete_Vitis_Path
    elif [[ "${COMP_CWORD}" -eq 4 ]]; then
        Regular_Completion "-o"
    fi
}


Complete_Cmd_State() {
    if [[ "${COMP_CWORD}" -eq 2 ]]; then
        Regular_Completion "--mp"
    fi
}


Complete_Cmd_Backup() {
    :
}


Complete_Cmd_Service() {
    if [[ "${COMP_CWORD}" -eq 2 ]]; then
        Regular_Completion "--update-autocategories --validate-checksums"
    elif [[ "${PREV}" == "--validate-checksums" ]]; then
        Regular_Completion "--fix"
    fi
}


Complete_Cmd_Delete() {
    SUBCOMMANDS_DELETE="-c -v"
    FLAGS_DELETE_C="--all-links -A --note -N"
    FLAGS_DELETE_V="--all-links -A --note -N -r"

    local FIRST_OPT=""
    local LAST_OPT=""
    for (( INDEX=1; INDEX<${COMP_CWORD}; INDEX++ )); do
        for OPT in ${SUBCOMMANDS_DELETE}; do
            if [[ ${COMP_WORDS[$INDEX]} == $OPT ]]; then
                if [[ -z $FIRST_OPT ]]; then
                    FIRST_OPT=$OPT
                fi
                LAST_OPT=$OPT
            fi
        done
    done
    unset INDEX
    if [[ "${CURR}" == -* && -n "${LAST_OPT}" ]]; then
        if [[ ${LAST_OPT} == "-v" && ${FIRST_OPT} == "-c" ]]; then
            Regular_Completion "--over"
        elif [[ ${LAST_OPT} == "-c" && ${FIRST_OPT} == "-v" ]]; then
            Regular_Completion "--over"
        elif [[ ${LAST_OPT} == "-v" ]]; then
            Regular_Completion "${FLAGS_DELETE_V}"
        else
            Regular_Completion "${FLAGS_DELETE_C}"
        fi
    elif [[ -z "${LAST_OPT}" ]]; then
        Regular_Completion "${SUBCOMMANDS_DELETE}"
    elif [[ "${LAST_OPT}" == "-v" ]]; then
        if [[ "${PREV}" == "-r" ]]; then
            # vitis delete -v <file> -r <relation>
            FILE_PATH=$(echo $(eval echo "${VTS_PATH}/${PREPREV}"))
            Complete_Relation_By_File "${FILE_PATH}"
        else
            Complete_Vitis_Path
        fi
    elif [[ "${LAST_OPT}" == "-c" ]]; then
        Complete_Category
    fi
}


Complete_Cmd_Mkfs() {
    local O1=""
    local O2=""
    local LAST_OPT=""
    for OPT in -i -s; do
        for (( index=1; index<${COMP_CWORD}; index++ )); do
            if [[ ${COMP_WORDS[$index]} == $OPT ]]; then
                [[ -z "$O1" ]] && O1="$OPT" || O2="$OPT"
                LAST_OPT="$OPT"
            fi
        done
    done
    if [[ ${COMP_CWORD} -eq 2 ]]; then
        Regular_Completion "-i -s --help"
    elif [[ "${O1}" == "-i" && "${O1}" != "${PREV}" && -z "${O2}" ]]; then
        Regular_Completion "-s"
    elif [[ "${O1}" == "-s" && "${O1}" != "${PREV}" && -z "${O2}" ]]; then
        Regular_Completion "-i"
    fi
}


Complete_Cmd_Mount() {
    local O1=""
    local O2=""
    local LAST_OPT=""
    for OPT in -i -b -m; do
        for (( index=1; index<${COMP_CWORD}; index++ )); do
            if [[ ${COMP_WORDS[$index]} == $OPT ]]; then
                [[ -z "$O1" ]] && O1="$OPT" || O2="$OPT"
                LAST_OPT="$OPT"
            fi
        done
    done
    if [[ ${COMP_CWORD} -eq 2 ]]; then
        Regular_Completion "-i -m -b --help"
        return
    fi
    if [[ "${O1}" == "-b" || "${O1}" == "-i" ]]; then
        if [[ "${O1}" != "${PREV}" && -z "${O2}" ]]; then
            Regular_Completion "-m --no-use-ac --use-ac-from"
            return
        fi
    fi
    if [[ "${O1}" == "-m" && "${O1}" != "${PREV}" && -z "${O2}" ]]; then
        Regular_Completion "-i -b"
    elif [[ -n "${O1}" && -n "${O2}" && "${PREV}" != "${O2}"  ]]; then
        Regular_Completion "--no-use-ac --use-ac-from"
    elif [[ "${CURR}" == "--*" ]]; then
        Regular_Completion "--no-use-ac --use-ac-from"
    fi
}


Complete_Cmd_Umount() {
    if [[ ${COMP_CWORD} -eq 2 ]]; then
        Regular_Completion "-i -m --help --force"
    fi
}


_vitis() {
    Define_Mount_Path
    CURR="${COMP_WORDS[COMP_CWORD]}"
    PREV="${COMP_WORDS[COMP_CWORD-1]}"
    PREPREV="${COMP_WORDS[COMP_CWORD-2]}"
    PREPREPREV="${COMP_WORDS[COMP_CWORD-3]}"

    if [[ ${COMP_CWORD} == 1 ]] ; then
        COMPREPLY=( $(compgen -W "${SUBCOMMANDS}" -- ${CURR}) )
        return 0
    fi

    local CMD="${COMP_WORDS[1]}"
    case "${CMD}" in
        show)    Complete_Cmd_Show     ;;
        open)    Complete_Cmd_Open     ;;
        run)     Complete_Cmd_Run      ;;
        create)  Complete_Cmd_Create   ;;
        assign)  Complete_Cmd_Assign   ;;
        rename)  Complete_Cmd_Rename   ;;
        move)    Complete_Cmd_Move     ;;
        delete)  Complete_Cmd_Delete   ;;
        mkfs)    Complete_Cmd_Mkfs     ;;
        mount)   Complete_Cmd_Mount    ;;
        umount)  Complete_Cmd_Umount   ;;
        copy)    Complete_Cmd_Copy     ;;
        state)   Complete_Cmd_State    ;;
        backup)  Complete_Cmd_Backup   ;;
        service) Complete_Cmd_Service  ;;
    esac
    return 0
}

complete -o default -F _vitis vitis
