#compdef tmuxinator mux
#autoload

local curcontext="$curcontext" state line ret=1
local -a _configs

_arguments -C \
  '1: :->cmds' \
  '2:: :->args' && ret=0

_configs=(${$(echo ~/.tmuxinator/*.yml):r:t})

case $state in
  cmds)
    _values "tmuxinator command" \
        "new[create a new project file and open it in your editor]" \
        "start[start a tmux session using project's tmuxinator config]" \
        "open[create a new project file and open it in your editor]" \
        "copy[copy source_project project file to a new project called new_project]" \
        "delete[deletes the project called project_name]" \
        "debug[output the shell commands generated by a projet]" \
        "implode[deletes all existing projects!]" \
        "list[list all existing projects]" \
        "doctor[look for problems in your configuration]" \
        "help[shows this help document]" \
        "version[shows tmuxinator version number]" \
        $_configs
    ret=0
    ;;
  args)
    case $line[1] in
      start|open|copy|delete|debug)
        [[ -n "$_configs" ]] && _values 'configs' $_configs
        ret=0
        ;;
    esac
    ;;
esac

return ret