Skip to content

Commit

Permalink
Add sign options
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
awerebea authored and wulfgarpro committed May 7, 2022
1 parent 851add8 commit 85baf12
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions history-sync.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -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
;;
Expand All @@ -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
Expand Down

0 comments on commit 85baf12

Please sign in to comment.