From c66f407507fa07fa2b97b9e207395f1f32f4cf40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Fri, 7 Jun 2024 07:17:41 +0300 Subject: [PATCH] feat(sops): add 3rd party fallback completion loader - https://github.com/urfave/cli/blob/v1-maint/docs/v1/manual.md#bash-completion - https://github.com/urfave/cli/blob/v1-maint/autocomplete/bash_autocomplete --- completions/Makefile.am | 1 + completions/_sops | 24 ++++++++++++++++++++++++ test/fallback/completions/Makefile.am | 1 + test/fallback/completions/sops | 1 + 4 files changed, 27 insertions(+) create mode 100644 completions/_sops create mode 120000 test/fallback/completions/sops diff --git a/completions/Makefile.am b/completions/Makefile.am index 2df4b18bf4f..a9f29074c17 100644 --- a/completions/Makefile.am +++ b/completions/Makefile.am @@ -409,6 +409,7 @@ bashcomp_DATA = 2to3 \ smartctl \ smbclient \ snownews \ + _sops \ sqlite3 \ ss \ ssh \ diff --git a/completions/_sops b/completions/_sops new file mode 100644 index 00000000000..6129759eecb --- /dev/null +++ b/completions/_sops @@ -0,0 +1,24 @@ +# 3rd party completion loader for commands using -*- shell-script -*- +# version 1 of the https://cli.urfave.org library. +# +# This serves as a fallback in case the completion is not installed otherwise. + +# https://github.com/urfave/cli/blob/v1-maint/docs/v1/manual.md#bash-completion +# https://github.com/urfave/cli/blob/v1-maint/autocomplete/bash_autocomplete +_comp_cmd__urfave_cli_v1() +{ + local cur prev words cword comp_args + _comp_initialize -- "$@" || return + + local compcmd=("${words[@]:0:cword}") + if [[ $cur == -* ]]; then + compcmd+=("$cur") + fi + compcmd+=(--generate-bash-completion) + + _comp_compgen_split -- "$("${compcmd[@]}" 2>/dev/null)" +} && + complete -o bashdefault -o default -o nospace \ + -F _comp_cmd__urfave_cli_v1 "$1" + +# ex: filetype=sh diff --git a/test/fallback/completions/Makefile.am b/test/fallback/completions/Makefile.am index 8efc9cc0ea7..160cdd58d4b 100644 --- a/test/fallback/completions/Makefile.am +++ b/test/fallback/completions/Makefile.am @@ -38,6 +38,7 @@ EXTRA_DIST = \ runuser \ rustup \ slackpkg \ + sops \ su \ svn \ svnadmin \ diff --git a/test/fallback/completions/sops b/test/fallback/completions/sops new file mode 120000 index 00000000000..d18b10cc121 --- /dev/null +++ b/test/fallback/completions/sops @@ -0,0 +1 @@ +../../../completions/_sops \ No newline at end of file