From 85baf12833a8239d275f94c98a6f01a95823dc48 Mon Sep 17 00:00:00 2001 From: awerebea Date: Tue, 15 Feb 2022 17:36:03 +0400 Subject: [PATCH] Add sign options Add the ability to explicitly specify the signing key using the -s argument. If any signing key is not specified, a prompt to sign with the first found key in the private key set is issued. If the -y option is given, sign without prompting. --- history-sync.plugin.zsh | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/history-sync.plugin.zsh b/history-sync.plugin.zsh index 8823b7a..7fcab47 100644 --- a/history-sync.plugin.zsh +++ b/history-sync.plugin.zsh @@ -175,12 +175,16 @@ function history_sync_pull() { function history_sync_push() { # Get options recipients, force local recipients=() + local signers=() local force=false - while getopts r:y opt; do + while getopts r:s:y opt; do case "$opt" in r) recipients+="$OPTARG" ;; + s) + signers+="$OPTARG" + ;; y) force=true ;; @@ -202,9 +206,34 @@ function history_sync_push() { for r in "${recipients[@]}"; do ENCRYPT_CMD+="-r \"$r\" " done + if [[ "${#signers[@]}" > 0 ]]; then + ENCRYPT_CMD+="--sign " + for s in "${signers[@]}"; do + ENCRYPT_CMD+="--default-key \"$s\" " + done + fi + + if [[ "$ENCRYPT_CMD" != *"--sign"* ]]; then + if [[ $force = false ]]; then + echo -n "$bold_color${fg[yellow]}Do you want to sign with first key found in secret keyring (y/N)?$reset_color " + read sign + else + sign='y' + fi + fi + + if [[ -n "$sign" ]]; then + case "$sign" in + [Yy]* ) + ENCRYPT_CMD+="--sign " + ;; + * ) + ;; + esac + fi if [[ "$ENCRYPT_CMD" =~ '.(-r).+.' ]]; then - ENCRYPT_CMD+="--encrypt --sign --armor --output $ZSH_HISTORY_FILE_ENC $ZSH_HISTORY_FILE" + ENCRYPT_CMD+="--encrypt --armor --output $ZSH_HISTORY_FILE_ENC $ZSH_HISTORY_FILE" eval "$ENCRYPT_CMD" if [[ "$?" != 0 ]]; then _print_gpg_encrypt_error_msg