Skip to content

Commit

Permalink
Fixed optarg specifier and updated usage function to unclude new forc…
Browse files Browse the repository at this point in the history
…e option
  • Loading branch information
wulfgarpro committed Apr 11, 2018
1 parent 1e12ef8 commit 2c901fb
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions history-sync.plugin.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ function _print_gpg_decrypt_error_msg() {
}

function _usage() {
echo "$bold_color${fg[red]}Usage: $0 [-r <string> -r <string>...]$reset_color" 1>&2
echo "Usage: [ [-r <string> ...] [-y] ]" 1>&2
echo
echo "Optional args:"
echo
echo " -r receipients"
echo " -y force"
return
}

Expand Down Expand Up @@ -80,10 +85,10 @@ function history_sync_pull() {

# Encrypt and push current history to master
function history_sync_push() {
# Get option recipients
# Get options recipients, force
local recipients=()
local force=false
while getopts yr: opt; do
while getopts r:y opt; do
case "$opt" in
r)
recipients+="$OPTARG"
Expand All @@ -104,10 +109,12 @@ function history_sync_push() {
read name
recipients+="$name"
fi

ENCRYPT_CMD="$GPG --yes -v "
for r in "${recipients[@]}"; do
ENCRYPT_CMD+="-r \"$r\" "
done

if [[ "$ENCRYPT_CMD" =~ '.(-r).+.' ]]; then
ENCRYPT_CMD+="--encrypt --sign --armor --output $ZSH_HISTORY_FILE_ENC $ZSH_HISTORY_FILE"
eval "$ENCRYPT_CMD"
Expand Down Expand Up @@ -150,6 +157,7 @@ function history_sync_push() {
;;
esac
fi

if [[ "$?" != 0 ]]; then
_print_git_error_msg
cd "$DIR"
Expand Down

0 comments on commit 2c901fb

Please sign in to comment.