_runit_sv() {
    local cur prev commands opts services
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    commands="status up down once \
    pause cont hup alarm interrupt quit 1 2 term kill exit \
    start stop reload restart shutdown \
    force-stop force-reload force-restart force-shutdown try-restart check"

    opts="-w -v"

    if [ -z "$SVDIR" ]; then
        services="$(ls -A /etc/service)"
    else
        services="$(ls -A "$SVDIR")"
    fi

    if [[ ${prev} == "sv" ]]; then
        COMPREPLY=( $(compgen -W "${commands}" -- ${cur}) )

    elif [[ ${cur} == -* ]] ; then
        COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )

    else
        COMPREPLY=( $(compgen -W "${services}" -- ${cur}) )
    fi
    return 0
}
complete -F _runit_sv sv