sops: add bash/zsh completion (#322572)

This commit is contained in:
Jörg Thalheim
2024-10-07 09:41:56 +02:00
committed by GitHub
3 changed files with 58 additions and 1 deletions
@@ -0,0 +1,19 @@
#!/usr/bin/env bash
# based on https://github.com/urfave/cli/blob/v2.3.0/autocomplete/bash_autocomplete
_cli_bash_autocomplete() {
if [[ "${COMP_WORDS[0]}" != "source" ]]; then
local cur opts
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
IFS=$'\n' read -d '' -ra COMPREPLY < <(compgen -W "${opts}" -- "${cur}")
return 0
fi
}
complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete sops
+14 -1
View File
@@ -1,4 +1,10 @@
{ lib, buildGoModule, fetchFromGitHub, nix-update-script }:
{
lib,
buildGoModule,
fetchFromGitHub,
installShellFiles,
nix-update-script,
}:
buildGoModule rec {
pname = "sops";
@@ -19,6 +25,13 @@ buildGoModule rec {
passthru.updateScript = nix-update-script { };
nativeBuildInputs = [ installShellFiles ];
postInstall = ''
installShellCompletion --cmd sops --bash ${./bash_autocomplete}
installShellCompletion --cmd sops --zsh ${./zsh_autocomplete}
'';
meta = with lib; {
homepage = "https://getsops.io/";
description = "Simple and flexible tool for managing secrets";
+25
View File
@@ -0,0 +1,25 @@
#compdef sops
## based on https://github.com/urfave/cli/blob/v2.3.0/autocomplete/zsh_autocomplete
_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 sops