diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-10-11 10:27:00 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-10-11 10:27:00 +0000 |
commit | 65aa53fc52ff15efe54df4147564828d535837f8 (patch) | |
tree | 31c51dad04fdcca80e6d3043c8bd49d2f1a51f83 /contrib/autocompletion | |
parent | Initial commit. (diff) | |
download | forgejo-upstream.tar.xz forgejo-upstream.zip |
Adding upstream version 8.0.3.HEADupstream/8.0.3upstreamdebian
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'contrib/autocompletion')
-rw-r--r-- | contrib/autocompletion/README | 17 | ||||
-rwxr-xr-x | contrib/autocompletion/bash_autocomplete | 30 | ||||
-rw-r--r-- | contrib/autocompletion/zsh_autocomplete | 30 |
3 files changed, 77 insertions, 0 deletions
diff --git a/contrib/autocompletion/README b/contrib/autocompletion/README new file mode 100644 index 00000000..1defd219 --- /dev/null +++ b/contrib/autocompletion/README @@ -0,0 +1,17 @@ +Bash and Zsh completion +======================= + +From within the gitea root run: + +```bash +source contrib/autocompletion/bash_autocomplete +``` + +or for zsh run: + +```bash +source contrib/autocompletion/zsh_autocomplete +``` + +These scripts will check if gitea is on the path and if so add autocompletion for `gitea`. Or if not autocompletion will work for `./gitea`. +If gitea has been installed as a different program pass in the `PROG` environment variable to set the correct program name. diff --git a/contrib/autocompletion/bash_autocomplete b/contrib/autocompletion/bash_autocomplete new file mode 100755 index 00000000..5cb62f26 --- /dev/null +++ b/contrib/autocompletion/bash_autocomplete @@ -0,0 +1,30 @@ +#! /bin/bash +# Heavily inspired by https://github.com/urfave/cli + +_cli_bash_autocomplete() { + if [[ "${COMP_WORDS[0]}" != "source" ]]; then + local cur opts base + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + if [[ "$cur" == "-"* ]]; then + opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion ) + else + opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion ) + fi + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + fi +} + +if [ -z "$PROG" ] && [ ! "$(command -v gitea &> /dev/null)" ] ; then + complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete gitea +elif [ -z "$PROG" ]; then + complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete ./gitea + complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete "$PWD/gitea" +else + complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete "$PROG" + unset PROG +fi + + + diff --git a/contrib/autocompletion/zsh_autocomplete b/contrib/autocompletion/zsh_autocomplete new file mode 100644 index 00000000..b3b40df5 --- /dev/null +++ b/contrib/autocompletion/zsh_autocomplete @@ -0,0 +1,30 @@ +#compdef ${PROG:=gitea} + + +# Heavily inspired by https://github.com/urfave/cli + +_cli_zsh_autocomplete() { + + local -a opts + local cur + cur=${words[-1]} + if [[ "$cur" == "-"* ]]; then + opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}") + else + opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}") + fi + + if [[ "${opts[1]}" != "" ]]; then + _describe 'values' opts + else + _files + fi + + return +} + +if [ -z $PROG ] ; then + compdef _cli_zsh_autocomplete gitea +else + compdef _cli_zsh_autocomplete $(basename $PROG) +fi |