Skip to content

Commit b4d8b8b

Browse files
authored
sops: add bash/zsh completion (#322572)
2 parents a825406 + c823621 commit b4d8b8b

File tree

3 files changed

+58
-1
lines changed

3 files changed

+58
-1
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/usr/bin/env bash
2+
# based on https://github.com/urfave/cli/blob/v2.3.0/autocomplete/bash_autocomplete
3+
4+
_cli_bash_autocomplete() {
5+
if [[ "${COMP_WORDS[0]}" != "source" ]]; then
6+
local cur opts
7+
COMPREPLY=()
8+
cur="${COMP_WORDS[COMP_CWORD]}"
9+
if [[ "$cur" == "-"* ]]; then
10+
opts=$("${COMP_WORDS[@]:0:$COMP_CWORD}" "${cur}" --generate-bash-completion)
11+
else
12+
opts=$("${COMP_WORDS[@]:0:$COMP_CWORD}" --generate-bash-completion)
13+
fi
14+
IFS=$'\n' read -d '' -ra COMPREPLY < <(compgen -W "${opts}" -- "${cur}")
15+
return 0
16+
fi
17+
}
18+
19+
complete -o bashdefault -o default -o nospace -F _cli_bash_autocomplete sops

pkgs/tools/security/sops/default.nix

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,10 @@
1-
{ lib, buildGoModule, fetchFromGitHub, nix-update-script }:
1+
{
2+
lib,
3+
buildGoModule,
4+
fetchFromGitHub,
5+
installShellFiles,
6+
nix-update-script,
7+
}:
28

39
buildGoModule rec {
410
pname = "sops";
@@ -19,6 +25,13 @@ buildGoModule rec {
1925

2026
passthru.updateScript = nix-update-script { };
2127

28+
nativeBuildInputs = [ installShellFiles ];
29+
30+
postInstall = ''
31+
installShellCompletion --cmd sops --bash ${./bash_autocomplete}
32+
installShellCompletion --cmd sops --zsh ${./zsh_autocomplete}
33+
'';
34+
2235
meta = with lib; {
2336
homepage = "https://getsops.io/";
2437
description = "Simple and flexible tool for managing secrets";
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#compdef sops
2+
3+
## based on https://github.com/urfave/cli/blob/v2.3.0/autocomplete/zsh_autocomplete
4+
5+
_cli_zsh_autocomplete() {
6+
7+
local -a opts
8+
local cur
9+
cur=${words[-1]}
10+
if [[ "$cur" == "-"* ]]; then
11+
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} ${cur} --generate-bash-completion)}")
12+
else
13+
opts=("${(@f)$(_CLI_ZSH_AUTOCOMPLETE_HACK=1 ${words[@]:0:#words[@]-1} --generate-bash-completion)}")
14+
fi
15+
16+
if [[ "${opts[1]}" != "" ]]; then
17+
_describe 'values' opts
18+
else
19+
_files
20+
fi
21+
22+
return
23+
}
24+
25+
compdef _cli_zsh_autocomplete sops

0 commit comments

Comments
 (0)