You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bash_autocomplete 946B

123456789101112131415161718192021222324252627282930
  1. #! /bin/bash
  2. # Heavily inspired by https://github.com/urfave/cli
  3. _cli_bash_autocomplete() {
  4. if [[ "${COMP_WORDS[0]}" != "source" ]]; then
  5. local cur opts base
  6. COMPREPLY=()
  7. cur="${COMP_WORDS[COMP_CWORD]}"
  8. if [[ "$cur" == "-"* ]]; then
  9. opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion )
  10. else
  11. opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
  12. fi
  13. COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
  14. return 0
  15. fi
  16. }
  17. if [ -z "$PROG" ] && [ ! "$(command -v gitea &> /dev/null)" ] ; then
  18. complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete gitea
  19. elif [ -z "$PROG" ]; then
  20. complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete ./gitea
  21. complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete "$PWD/gitea"
  22. else
  23. complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete "$PROG"
  24. unset PROG
  25. fi