#!/usr/bin/env bash

_kontena_complete() {
  COMPREPLY=()
  if [ "$ZSH_VERSION" == "" ]; then
    local src="${BASH_SOURCE[0]}"
  else
    local src="${(%):-%x}"
  fi
  DIR=$( cd "$( dirname "$src" )" && pwd )
  local word="${COMP_WORDS[COMP_CWORD]}"
  local completions="$(${DIR}/completer ${COMP_WORDS[*]})"
  COMPREPLY=( $(compgen -W "$completions" -- "$word") )
}

if [ "$ZSH_VERSION" != "" ]; then
  autoload -U +X compinit && compinit
  autoload -U +X bashcompinit && bashcompinit
fi

complete -F _kontena_complete kontena
