From b313b0a145e202312540015b2d5f4b367d8015f2 Mon Sep 17 00:00:00 2001 From: decentral1se Date: Sun, 27 Oct 2024 08:54:43 +0100 Subject: [PATCH] fix: use old auto-completion for 0.9.x compat See https://git.coopcloud.tech/toolshed/organising/issues/644 Partial revert of 1f8662cd9518c3d1e14d058f2a88d438b59170b2 --- scripts/autocomplete/bash | 22 ++++--------------- scripts/autocomplete/fish | 2 +- scripts/autocomplete/powershell | 2 +- scripts/autocomplete/zsh | 39 +++++++++++++++------------------ 4 files changed, 24 insertions(+), 41 deletions(-) mode change 100755 => 100644 scripts/autocomplete/bash diff --git a/scripts/autocomplete/bash b/scripts/autocomplete/bash old mode 100755 new mode 100644 index 7120a0d2..f0f62418 --- a/scripts/autocomplete/bash +++ b/scripts/autocomplete/bash @@ -2,31 +2,17 @@ : ${PROG:=$(basename ${BASH_SOURCE})} -# Macs have bash3 for which the bash-completion package doesn't include -# _init_completion. This is a minimal version of that function. -_cli_init_completion() { - COMPREPLY=() - _get_comp_words_by_ref "$@" cur prev words cword -} - _cli_bash_autocomplete() { if [[ "${COMP_WORDS[0]}" != "source" ]]; then - local cur opts base words + local cur opts base COMPREPLY=() cur="${COMP_WORDS[COMP_CWORD]}" - if declare -F _init_completion >/dev/null 2>&1; then - _init_completion -n "=:" || return - else - _cli_init_completion -n "=:" || return - fi - words=("${words[@]:0:$cword}") if [[ "$cur" == "-"* ]]; then - requestComp="${words[*]} ${cur} --generate-shell-completion" + opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} ${cur} --generate-bash-completion ) else - requestComp="${words[*]} --generate-shell-completion" + opts=$( ${COMP_WORDS[@]:0:$COMP_CWORD} --generate-bash-completion ) fi - opts=$(eval "${requestComp}" 2>/dev/null) - COMPREPLY=($(compgen -W "${opts}" -- ${cur})) + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) return 0 fi } diff --git a/scripts/autocomplete/fish b/scripts/autocomplete/fish index c40fae9d..54427187 100644 --- a/scripts/autocomplete/fish +++ b/scripts/autocomplete/fish @@ -1,5 +1,5 @@ function complete_abra_args - set -l cmd (commandline -poc) --generate-shell-completion + set -l cmd (commandline -poc) --generate-bash-completion $cmd end complete -c abra -f -n "not __fish_seen_subcommand_from -h --help -v --version complete_abra_args" -a "(complete_abra_args)" diff --git a/scripts/autocomplete/powershell b/scripts/autocomplete/powershell index 6e0c422e..cfffbf4f 100644 --- a/scripts/autocomplete/powershell +++ b/scripts/autocomplete/powershell @@ -2,7 +2,7 @@ $fn = $($MyInvocation.MyCommand.Name) $name = $fn -replace "(.*)\.ps1$", '$1' Register-ArgumentCompleter -Native -CommandName $name -ScriptBlock { param($commandName, $wordToComplete, $cursorPosition) - $other = "$wordToComplete --generate-shell-completion" + $other = "$wordToComplete --generate-bash-completion" Invoke-Expression $other | ForEach-Object { [System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_) } diff --git a/scripts/autocomplete/zsh b/scripts/autocomplete/zsh index 57f19d37..cf39c888 100644 --- a/scripts/autocomplete/zsh +++ b/scripts/autocomplete/zsh @@ -1,26 +1,23 @@ -#compdef abra -compdef _abra abra +#compdef $PROG -# https://github.com/urfave/cli/blob/main/autocomplete/zsh_autocomplete +_cli_zsh_autocomplete() { -_abra() { - local -a opts - local cur - cur=${words[-1]} - if [[ "$cur" == "-"* ]]; then - opts=("${(@f)$(${words[@]:0:#words[@]-1} ${cur} --generate-shell-completion)}") - else - opts=("${(@f)$(${words[@]:0:#words[@]-1} --generate-shell-completion)}") - fi + 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 + if [[ "${opts[1]}" != "" ]]; then + _describe 'values' opts + else + _files + fi + + return } -# don't run the completion function when being source-ed or eval-ed -if [ "$funcstack[1]" = "_abra" ]; then - _abra -fi +compdef _cli_zsh_autocomplete $PROG