Unverified Commit b4d8b8b3 authored by Jörg Thalheim's avatar Jörg Thalheim Committed by GitHub
Browse files

sops: add bash/zsh completion (#322572)

parents a825406b c8236211
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
#!/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
Original line number Diff line number Diff line
{ 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 −0
Original line number Diff line number Diff line
#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