Skip to content

Commit 4a25324

Browse files
committed
add generated autocomplete scripts for shells
1 parent 829f53d commit 4a25324

File tree

3 files changed

+618
-43
lines changed

3 files changed

+618
-43
lines changed
Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,34 @@
1-
#! /bin/bash
2-
# Heavily inspired by https://github.com/urfave/cli
1+
#!/bin/bash
32

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() {
513
if [[ "${COMP_WORDS[0]}" != "source" ]]; then
6-
local cur opts base
14+
local cur opts base words
715
COMPREPLY=()
816
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}")
923
if [[ "$cur" == "-"* ]]; then
10-
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion )
24+
requestComp="${words[*]} ${cur} --generate-shell-completion"
1125
else
12-
opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion )
26+
requestComp="${words[*]} --generate-shell-completion"
1327
fi
14-
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
28+
opts=$(eval "${requestComp}" 2>/dev/null)
29+
COMPREPLY=($(compgen -W "${opts}" -- ${cur}))
1530
return 0
1631
fi
1732
}
1833

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

Comments
 (0)