|
1 | | -#! /bin/bash |
2 | | -# Heavily inspired by https://github.com/urfave/cli |
| 1 | +#!/bin/bash |
3 | 2 |
|
4 | | -_cli_bash_autocomplete() { |
| 3 | +# This is a shell completion script auto-generated by https://github.com/urfave/cli for bash. |
| 4 | + |
| 5 | +# Macs have bash3 for which the bash-completion package doesn't include |
| 6 | +# _init_completion. This is a minimal version of that function. |
| 7 | +__gitea_init_completion() { |
| 8 | + COMPREPLY=() |
| 9 | + _get_comp_words_by_ref "$@" cur prev words cword |
| 10 | +} |
| 11 | + |
| 12 | +__gitea_bash_autocomplete() { |
5 | 13 | if [[ "${COMP_WORDS[0]}" != "source" ]]; then |
6 | | - local cur opts base |
| 14 | + local cur opts base words |
7 | 15 | COMPREPLY=() |
8 | 16 | cur="${COMP_WORDS[COMP_CWORD]}" |
| 17 | + if declare -F _init_completion >/dev/null 2>&1; then |
| 18 | + _init_completion -n "=:" || return |
| 19 | + else |
| 20 | + __gitea_init_completion -n "=:" || return |
| 21 | + fi |
| 22 | + words=("${words[@]:0:$cword}") |
9 | 23 | if [[ "$cur" == "-"* ]]; then |
10 | | - opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion ) |
| 24 | + requestComp="${words[*]} ${cur} --generate-shell-completion" |
11 | 25 | else |
12 | | - opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion ) |
| 26 | + requestComp="${words[*]} --generate-shell-completion" |
13 | 27 | fi |
14 | | - COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) |
| 28 | + opts=$(eval "${requestComp}" 2>/dev/null) |
| 29 | + COMPREPLY=($(compgen -W "${opts}" -- ${cur})) |
15 | 30 | return 0 |
16 | 31 | fi |
17 | 32 | } |
18 | 33 |
|
19 | | -if [ -z "$PROG" ] && [ ! "$(command -v gitea &> /dev/null)" ] ; then |
20 | | - complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete gitea |
21 | | -elif [ -z "$PROG" ]; then |
22 | | - complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete ./gitea |
23 | | - complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete "$PWD/gitea" |
24 | | -else |
25 | | - complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete "$PROG" |
26 | | - unset PROG |
27 | | -fi |
28 | | - |
29 | | - |
30 | | - |
| 34 | +complete -o bashdefault -o default -o nospace -F __gitea_bash_autocomplete gitea |
0 commit comments