# bash completion for sr — generated by `sr completions bash`
# Install: sr completions bash --install
_sr_completion() {
  local cur prev words cword
  COMPREPLY=()
  cur="${COMP_WORDS[COMP_CWORD]}"
  prev="${COMP_WORDS[COMP_CWORD-1]}"

  # Options that take a value: complete the value, not another flag.
  case "$prev" in
    --color|--verbosity|--encoding-error|--line-endings|--write|--pattern-kind|--channel|--source)
      COMPREPLY=( $(compgen -W "always auto crlf debug dir ere fixed ignore in-place lf never normal pcre preserve quiet regex replace stdout strict verbose auto" -- "$cur") )
      return 0
      ;;
    --target|-C|--output-dir|-o|--backup-dir|--files-from|--config-file)
      COMPREPLY=( $(compgen -d -f -- "$cur") )
      return 0
      ;;
    --help)
      COMPREPLY=( $(compgen -W "topics options examples matching backup rollback sessions update config json exit-codes env install" -- "$cur") )
      return 0
      ;;
  esac

  local cmd=""
  local i=1
  while [ $i -lt $COMP_CWORD ]; do
    local word="${COMP_WORDS[i]}"
    case "$word" in
      -*) ;;
      *) cmd="$word"; break ;;
    esac
    i=$((i+1))
  done

  if [ -z "$cmd" ]; then
    if [[ "$cur" == -* ]]; then
      COMPREPLY=( $(compgen -W "--color --json --quiet --verbose --verbosity --help --help-all --version --json --porcelain --no-color --no-update-check --config --config-file --debug" -- "$cur") )
    else
      COMPREPLY=( $(compgen -W "replace find diff rename rollback sessions update doctor completions config selftest help backups diagnose grep mv r restore search smoke undo upgrade" -- "$cur") $(compgen -d -f -- "$cur") )
    fi
    return 0
  fi

  local opts=""
  case "$cmd" in
    replace)
      opts="--allow-root --atomic --backup --backup-dir --binary --color --confirm-threshold --context --diff --dry-run --encoding --encoding-error --ere --exclude --exclude-dir --file --files-from --force --gitignore --hidden --ignore-case --include --interactive --json --keep --keep-age --line-endings --line-range --lock --max-count --max-depth --max-size --min-size --multiline --newer-than --no-atomic --no-backup --no-default-excludes --no-escapes --no-global --no-lock --no-progress --no-recursive --no-summary --older-than --output-dir --pattern --pattern-kind --pcre --porcelain --preserve-mtime --progress --quiet --regex --rename --rename-only --suffix --summary --symlinks --target --verbose --verbosity --word-boundary --write --yes -1 -C -E -I -L -M -R -f -i -m -n -o -p -q -v -w -y --help"
      ;;
    find)
      opts="--binary --color --context --diff --dry-run --encoding --encoding-error --ere --exclude --exclude-dir --file --files-from --gitignore --hidden --ignore-case --include --interactive --json --line-range --max-count --max-depth --max-size --min-size --multiline --newer-than --no-default-excludes --no-escapes --no-global --no-progress --no-recursive --no-summary --older-than --pattern --pattern-kind --pcre --porcelain --progress --quiet --regex --summary --symlinks --target --verbose --verbosity --word-boundary -1 -C -E -I -L -M -R -i -m -n -p -q -v -w"
      ;;
    diff)
      opts="--binary --color --context --diff --dry-run --encoding --encoding-error --ere --exclude --exclude-dir --file --files-from --gitignore --hidden --ignore-case --include --interactive --json --line-range --max-count --max-depth --max-size --min-size --multiline --newer-than --no-default-excludes --no-escapes --no-global --no-progress --no-recursive --no-summary --older-than --pattern --pattern-kind --pcre --porcelain --progress --quiet --regex --summary --symlinks --target --verbose --verbosity --word-boundary -1 -C -E -I -L -M -R -i -m -n -p -q -v -w"
      ;;
    rename)
      opts="--allow-root --backup --backup-dir --binary --color --confirm-threshold --context --diff --dry-run --encoding --encoding-error --ere --exclude --exclude-dir --file --files-from --force --gitignore --hidden --ignore-case --include --interactive --json --keep --keep-age --line-range --lock --max-count --max-depth --max-size --min-size --multiline --newer-than --no-backup --no-default-excludes --no-escapes --no-global --no-lock --no-progress --no-recursive --no-summary --older-than --pattern --pattern-kind --pcre --porcelain --progress --quiet --regex --summary --symlinks --target --verbose --verbosity --word-boundary --yes -1 -C -E -I -L -M -R -f -i -m -n -p -q -v -w -y"
      ;;
    rollback)
      opts="--color --force --json --quiet --verbose --verbosity --yes -f -q -v -y"
      ;;
    sessions)
      opts="--color --json --keep --keep-age --quiet --verbose --verbosity --yes -q -v -y"
      ;;
    update)
      opts="--color --json --quiet --verbose --verbosity --yes -q -v -y"
      ;;
    doctor)
      opts="--color --json --quiet --verbose --verbosity -q -v"
      ;;
    completions)
      opts="--color --json --quiet --verbose --verbosity -q -v"
      ;;
    config)
      opts="--color --json --quiet --verbose --verbosity -q -v"
      ;;
    selftest)
      opts="--color --json --quiet --verbose --verbosity -q -v"
      ;;
    help)
      opts="--color --json --quiet --verbose --verbosity -q -v"
      ;;
    *)
      opts="--color --json --quiet --verbose --verbosity --help --help-all --version --json --porcelain --no-color --no-update-check --config --config-file --debug"
      ;;
  esac

  if [[ "$cur" == -* ]]; then
    COMPREPLY=( $(compgen -W "$opts --color --json --quiet --verbose --verbosity --help --help-all --version --json --porcelain --no-color --no-update-check --config --config-file --debug" -- "$cur") )
  else
    COMPREPLY=( $(compgen -d -f -- "$cur") )
  fi
  return 0
}
complete -F _sr_completion sr
