From ffd3b9ed7b43627bc7f46ca9bc7e93add072e6bb Mon Sep 17 00:00:00 2001 From: Bartek Pacia Date: Wed, 30 Oct 2024 23:39:32 +0100 Subject: [PATCH] update completion scripts for urfave/cli/v3 follow up of cab383f92a7d42af03c1e9d3fddc6328658f0dff --- autocomplete/bash_autocomplete_fhome | 21 +++++++++-------- autocomplete/bash_autocomplete_fhomed | 21 +++++++++-------- autocomplete/zsh_autocomplete_fhome | 34 +++++++++++++++++---------- autocomplete/zsh_autocomplete_fhomed | 33 ++++++++++++++++---------- 4 files changed, 64 insertions(+), 45 deletions(-) diff --git a/autocomplete/bash_autocomplete_fhome b/autocomplete/bash_autocomplete_fhome index baa5034..e80b0fe 100644 --- a/autocomplete/bash_autocomplete_fhome +++ b/autocomplete/bash_autocomplete_fhome @@ -1,15 +1,13 @@ -#! /bin/bash - -: ${PROG:=fhome} +#!/usr/bin/env bash # 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() { +__fallback_init_completion() { COMPREPLY=() _get_comp_words_by_ref "$@" cur prev words cword } -_cli_bash_autocomplete() { +__start-fhome() { if [[ "${COMP_WORDS[0]}" != "source" ]]; then local cur opts base words COMPREPLY=() @@ -17,13 +15,13 @@ _cli_bash_autocomplete() { if declare -F _init_completion >/dev/null 2>&1; then _init_completion -n "=:" || return else - _cli_init_completion -n "=:" || return + __fallback_init_completion -n "=:" || return fi words=("${words[@]:0:$cword}") if [[ "$cur" == "-"* ]]; then - requestComp="${words[*]} ${cur} --generate-bash-completion" + requestComp="${words[*]} ${cur} --generate-shell-completion" else - requestComp="${words[*]} --generate-bash-completion" + requestComp="${words[*]} --generate-shell-completion" fi opts=$(eval "${requestComp}" 2>/dev/null) COMPREPLY=($(compgen -W "${opts}" -- ${cur})) @@ -31,5 +29,8 @@ _cli_bash_autocomplete() { fi } -complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG -unset PROG +if [[ $(type -t compopt) = "builtin" ]]; then + complete -o default -F __start-fhome fhome +else + complete -o default -o nospace -F __start-fhome fhome +fi diff --git a/autocomplete/bash_autocomplete_fhomed b/autocomplete/bash_autocomplete_fhomed index 6ffd28a..60314f6 100644 --- a/autocomplete/bash_autocomplete_fhomed +++ b/autocomplete/bash_autocomplete_fhomed @@ -1,15 +1,13 @@ -#! /bin/bash - -: ${PROG:=fhomed} +#!/usr/bin/env bash # 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() { +__fallback_init_completion() { COMPREPLY=() _get_comp_words_by_ref "$@" cur prev words cword } -_cli_bash_autocomplete() { +__start-fhomed() { if [[ "${COMP_WORDS[0]}" != "source" ]]; then local cur opts base words COMPREPLY=() @@ -17,13 +15,13 @@ _cli_bash_autocomplete() { if declare -F _init_completion >/dev/null 2>&1; then _init_completion -n "=:" || return else - _cli_init_completion -n "=:" || return + __fallback_init_completion -n "=:" || return fi words=("${words[@]:0:$cword}") if [[ "$cur" == "-"* ]]; then - requestComp="${words[*]} ${cur} --generate-bash-completion" + requestComp="${words[*]} ${cur} --generate-shell-completion" else - requestComp="${words[*]} --generate-bash-completion" + requestComp="${words[*]} --generate-shell-completion" fi opts=$(eval "${requestComp}" 2>/dev/null) COMPREPLY=($(compgen -W "${opts}" -- ${cur})) @@ -31,5 +29,8 @@ _cli_bash_autocomplete() { fi } -complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete $PROG -unset PROG +if [[ $(type -t compopt) = "builtin" ]]; then + complete -o default -F __start-fhomed fhomed +else + complete -o default -o nospace -F __start-fhomed fhomed +fi diff --git a/autocomplete/zsh_autocomplete_fhome b/autocomplete/zsh_autocomplete_fhome index f5cba4f..bc0a007 100644 --- a/autocomplete/zsh_autocomplete_fhome +++ b/autocomplete/zsh_autocomplete_fhome @@ -1,17 +1,25 @@ #compdef fhome +compdef _fhome fhome -local -a opts -local cur -cur=${words[-1]} -if [[ "$cur" == "-"* ]]; then - opts=("${(@f)$(${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}") -else - opts=("${(@f)$(${words[@]:0:#words[@]-1} --generate-bash-completion)}") -fi +_fhome() { + 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 -if [[ "${opts[1]}" != "" ]]; then - _describe 'values' opts -else - _files -fi + if [[ "${opts[1]}" != "" ]]; then + _describe 'values' opts + else + _files + fi +} +# Don't run the completion function when being source-ed or eval-ed. +# See https://github.com/urfave/cli/issues/1874 for discussion. +if [ "$funcstack[1]" = "_fhome" ]; then + _fhome +fi diff --git a/autocomplete/zsh_autocomplete_fhomed b/autocomplete/zsh_autocomplete_fhomed index f8b7010..a494052 100644 --- a/autocomplete/zsh_autocomplete_fhomed +++ b/autocomplete/zsh_autocomplete_fhomed @@ -1,16 +1,25 @@ #compdef fhomed +compdef _fhomed fhomed -local -a opts -local cur -cur=${words[-1]} -if [[ "$cur" == "-"* ]]; then - opts=("${(@f)$(${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}") -else - opts=("${(@f)$(${words[@]:0:#words[@]-1} --generate-bash-completion)}") -fi +_fhomed() { + 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 + + if [[ "${opts[1]}" != "" ]]; then + _describe 'values' opts + else + _files + fi +} -if [[ "${opts[1]}" != "" ]]; then - _describe 'values' opts -else - _files +# Don't run the completion function when being source-ed or eval-ed. +# See https://github.com/urfave/cli/issues/1874 for discussion. +if [ "$funcstack[1]" = "_fhomed" ]; then + _fhomed fi