From f727a5f97ca62c5891e6f4947ba6d7b0352aa5a7 Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Sun, 29 Sep 2024 20:55:01 +0300 Subject: [PATCH] Gpg : Fix bash functions default args to match documentation. --- home/program/bash/module/Gpg.nix | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/home/program/bash/module/Gpg.nix b/home/program/bash/module/Gpg.nix index 1ef009f..0220536 100644 --- a/home/program/bash/module/Gpg.nix +++ b/home/program/bash/module/Gpg.nix @@ -5,10 +5,14 @@ function encrypt() { local IFS=$'\n' local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=($(_ls_file)) + + if [[ "''${targets}" = "" ]]; then + help encrypt + return 2 + fi process() { - gpg --encrypt --armor --recipient hi@voronind.com --output "''${target}.enc" "''${target}" + gpg --encrypt --armor --recipient hi@voronind.com --output "''${target}.gpg" "''${target}" } _iterate_targets process ''${targets[@]} @@ -19,10 +23,14 @@ function decrypt() { local IFS=$'\n' local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=($(_ls_file)) + + if [[ "''${targets}" = "" ]]; then + help decrypt + return 2 + fi process() { - gpg --decrypt --output "''${target%.enc}" "''${target}" + gpg --decrypt --output "''${target%.gpg}" "''${target}" } _iterate_targets process ''${targets[@]} @@ -33,7 +41,11 @@ function sign() { local IFS=$'\n' local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=($(_ls_file)) + + if [[ "''${targets}" = "" ]]; then + help sign + return 2 + fi process() { gpg --detach-sig --armor --output "''${target}.sig" "''${target}" @@ -42,11 +54,12 @@ _iterate_targets process ''${targets[@]} } - # Verify a signature. - # Usage: verify + # Verify a signature. All .sig files by default. + # Usage: verify [FILES] function verify() { local IFS=$'\n' local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=(*.sig) process() {