# /usr/share/bash-completion/completions/chdist
# Bash command completion for ‘chdist(1)’.
# Documentation: ‘bash(1)’, section “Programmable Completion”.

_chdist ()
{
  local cur prev words cword
  _init_completion || return

  local options='-a --arch -d --data-dir -h --help --version'
  local commands='create list
    apt apt-get apt-cache apt-file apt-rdepends build-rdeps aptitude
    src2bin bin2src
    compare-packages compare-bin-packages
    compare-versions compare-bin-versions
    grep-dctrl-packages grep-dctrl-sources'
  # Sync'd with https://buildd.debian.org/status/package.php?p=dpkg&suite=sid on 2026-02-12
  local cur_archs="all amd64 arm64 armhf i386 loong64 ppc64el riscv64 s390x alpha hppa hurd-amd64 hurd-i386 m68k powerpc ppc64 sh4 sparc64 x32"
  local old_archs="armel ia64 kfreebsd-amd64 kfreebsd-i386 mips mips64el mipsel powerpcspe ppc64el s390 sparc"
  local archs="$cur_archs $old_archs"
  local dists=$(ls ~/.chdist 2>/dev/null)

  COMPREPLY=()

  case "$prev" in
    -a|--arch)
      COMPREPLY=( $( compgen -W "$archs" -- $cur ) )
      return 0
      ;;
    -d|--data-dir)
      _filedir
      return 0
      ;;
    -h|--help|--version)
      return 0
      ;;
    list)
      # command without args
      return 0
      ;;
  esac

  if [[ "$cur" == -* ]]; then
    # return one of the possible options
    COMPREPLY=( $( compgen -W "$options" -- $cur ) )
  elif [[ "$dists" =~ (^|[[:space:]])$prev([[:space:]]|$) ]] && (( cword == 2 )); then
    # syntax 'chdist DIST COMMAND': return one of the possible commands
    COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
  elif [[ "$commands" =~ (^|[[:space:]])$prev([[:space:]]|$) ]] && (( cword == 2 )); then
    # syntax 'chdist COMMAND DIST': return one of the possible dists
    COMPREPLY=( $( compgen -W "$dists" -- $cur ) )
  else
    # return one of the possible commands or dists
    COMPREPLY=( $( compgen -W "$commands $dists" -- $cur ) )
  fi

  return 0
} &&
complete -F _chdist chdist


# Local variables:
# coding: utf-8
# mode: shell-script
# indent-tabs-mode: nil
# End:
# vim: fileencoding=utf-8 filetype=sh expandtab shiftwidth=4 :
