# wnlctl(1) completion                                      -*- shell-script -*-

_wnlctl_completion() {
  local cur
  local RUNTIME_DIR="${XDG_RUNTIME_DIR:-/tmp}"
  COMPREPLY=()
  cur="${COMP_WORDS[COMP_CWORD]}"

  if [ "$COMP_CWORD" -eq 1 ]; then
    local files=("$RUNTIME_DIR"/wnl_slot_*.sock)
    local numbers=()
    for file in "${files[@]}"; do
      if [[ $file =~ "$RUNTIME_DIR"/wnl_slot_([0-9]+).sock ]]; then
        numbers+=("${BASH_REMATCH[1]}")
      fi
    done
    # shellcheck disable=SC2207
    COMPREPLY=( $(compgen -W "${numbers[*]}" -- "$cur") )
  fi
}

complete -F _wnlctl_completion wnlctl

# ex: filetype=sh
