_ectl()
{
    local cur first services options

    cur=`_get_cword`
    first=${COMP_WORDS[1]}

    services=( $(systemctl list-units -a --plain --no-legend 'entangle@*' | sed -E 's/entangle@(.*?).service .*/\1/') )
    options=( restart status start stop reload log )

    case "$first" in
	reload)
	    ;;
	restart|start|stop|status|r|s)
            COMPREPLY=( $( compgen -W '${services[@]}' -- $cur ) )
	    ;;
	*)
            COMPREPLY=( $( compgen -W '${options[@]}' -- $cur ) )
	    ;;
    esac

    return 0
} &&
complete -F _ectl ectl
