_vm_tui() {
  local cur prev
  cur=${COMP_WORDS[COMP_CWORD]}
  prev=${COMP_WORDS[COMP_CWORD-1]}
  case $prev in
    -info)
      COMPREPLY=($(compgen -W "$(vm-tui -list 2>/dev/null | awk 'NR > 1 { print $1 }')" -- "$cur"))
      return ;;
    -describe)
      COMPREPLY=($(compgen -W "$(vm-tui -catalogue 2>/dev/null | awk '/^  / { print $1 }')" -- "$cur"))
      return ;;
    -section)
      COMPREPLY=($(compgen -W "guests switches storage media templates settings" -- "$cur"))
      return ;;
    -refresh)
      return ;;
  esac
  if [[ $cur == -* ]]; then
    COMPREPLY=($(compgen -W "-refresh -section -list -info -switches -json -catalogue -describe -version" -- "$cur"))
  else
    COMPREPLY=($(compgen -W "$(vm-tui -list 2>/dev/null | awk 'NR > 1 { print $1 }')" -- "$cur"))
  fi
}
complete -F _vm_tui vm-tui
