From cd5829699512d0aa4d5df9d60b011d39d40576dd Mon Sep 17 00:00:00 2001 From: TheFox0x7 Date: Tue, 26 Aug 2025 23:15:36 +0000 Subject: [PATCH] revert completion scripts removal (#808) partial revert of: https://gitea.com/gitea/tea/pulls/782 closes: https://gitea.com/gitea/tea/issues/784 Old versions of tea have hardcoded completion fetched from main branch Those should not be used from v0.10 onward. Co-authored-by: Lunny Xiao Reviewed-on: https://gitea.com/gitea/tea/pulls/808 Reviewed-by: Lunny Xiao Co-authored-by: TheFox0x7 Co-committed-by: TheFox0x7 --- contrib/autocomplete.ps1 | 9 +++++++++ contrib/autocomplete.sh | 21 +++++++++++++++++++++ contrib/autocomplete.zsh | 23 +++++++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 contrib/autocomplete.ps1 create mode 100644 contrib/autocomplete.sh create mode 100644 contrib/autocomplete.zsh diff --git a/contrib/autocomplete.ps1 b/contrib/autocomplete.ps1 new file mode 100644 index 0000000..81812a6 --- /dev/null +++ b/contrib/autocomplete.ps1 @@ -0,0 +1,9 @@ +$fn = $($MyInvocation.MyCommand.Name) +$name = $fn -replace "(.*)\.ps1$", '$1' +Register-ArgumentCompleter -Native -CommandName $name -ScriptBlock { + param($commandName, $wordToComplete, $cursorPosition) + $other = "$wordToComplete --generate-bash-completion" + Invoke-Expression $other | ForEach-Object { + [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) + } + } \ No newline at end of file diff --git a/contrib/autocomplete.sh b/contrib/autocomplete.sh new file mode 100644 index 0000000..f0f6241 --- /dev/null +++ b/contrib/autocomplete.sh @@ -0,0 +1,21 @@ +#! /bin/bash + +: ${PROG:=$(basename ${BASH_SOURCE})} + +_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 +} + +complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG +unset PROG diff --git a/contrib/autocomplete.zsh b/contrib/autocomplete.zsh new file mode 100644 index 0000000..cf39c88 --- /dev/null +++ b/contrib/autocomplete.zsh @@ -0,0 +1,23 @@ +#compdef $PROG + +_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 +} + +compdef _cli_zsh_autocomplete $PROG