diff options
-rwxr-xr-x | otp.bash | 17 | ||||
-rw-r--r-- | pass-otp.1 | 6 | ||||
-rw-r--r-- | pass-otp.bash.completion | 2 | ||||
-rwxr-xr-x | test/code.t | 11 | ||||
-rw-r--r-- | test/setup.sh | 5 |
5 files changed, 32 insertions, 9 deletions
@@ -130,7 +130,7 @@ otp_read_secret() { } otp_insert() { - local path="$1" passfile="$2" contents="$3" message="$4" + local path="$1" passfile="$2" contents="$3" message="$4" quiet="$5" check_sneaky_paths "$path" set_git "$passfile" @@ -140,7 +140,11 @@ otp_insert() { echo "$contents" | $GPG -e "${GPG_RECIPIENT_ARGS[@]}" -o "$passfile" "${GPG_OPTS[@]}" || die "OTP secret encryption aborted." - git_add_file "$passfile" "$message" + if [[ "$quiet" -eq 1 ]]; then + git_add_file "$passfile" "$message" 1>/dev/null + else + git_add_file "$passfile" "$message" + fi } cmd_otp_usage() { @@ -311,16 +315,17 @@ cmd_otp_append() { cmd_otp_code() { [[ -z "$OATH" ]] && die "Failed to generate OTP code: oathtool is not installed." - local opts clip=0 - opts="$($GETOPT -o c -l clip -n "$PROGRAM" -- "$@")" + local opts clip=0 quiet=0 + opts="$($GETOPT -o cq -l clip,quiet -n "$PROGRAM" -- "$@")" local err=$? eval set -- "$opts" while true; do case $1 in -c|--clip) clip=1; shift ;; + -q|--quiet) quiet=1; shift ;; --) shift; break ;; esac done - [[ $err -ne 0 || $# -ne 1 ]] && die "Usage: $PROGRAM $COMMAND [--clip,-c] pass-name" + [[ $err -ne 0 || $# -ne 1 ]] && die "Usage: $PROGRAM $COMMAND [--clip,-c] [--quiet,-q] pass-name" local path="${1%/}" local passfile="$PREFIX/$path.gpg" @@ -368,7 +373,7 @@ cmd_otp_code() { replaced+="$line" done < <(echo "$contents") - otp_insert "$path" "$passfile" "$replaced" "Increment HOTP counter for $path." + otp_insert "$path" "$passfile" "$replaced" "Increment HOTP counter for $path." "$quiet" fi if [[ $clip -ne 0 ]]; then @@ -28,13 +28,15 @@ If no COMMAND is specified, COMMAND defaults to \fBcode\fP. .SH COMMANDS .TP -\fBotp code\fP [ \fI--clip\fP, \fI-c\fP ] \fIpass-name\fP +\fBotp code\fP [ \fI--clip\fP, \fI-c\fP ] [ \fI--quiet\fP, \fI-q\fP ] \fIpass-name\fP Generate and print an OTP code from the secret key stored in \fIpass-name\fP using \fBoathtool\fP(1). If \fI--clip\fP or \fI-c\fP is specified, do not print the code but instead copy it to the clipboard using \fBxclip\fP(1) and then restore the clipboard after 45 (or \fIPASSWORD_STORE_CLIP_TIME\fP) -seconds. This command is alternatively named \fBshow\fP. +seconds. If \fI--quiet\fP or \fI-q\fP is specified, do not print +the git update message to standard out. This command is alternatively named +\fBshow\fP. .TP \fBotp insert\fP [ \fI--force\fP, \fI-f\fP ] [ \fI--echo\fP, \fI-e\fP ] \ diff --git a/pass-otp.bash.completion b/pass-otp.bash.completion index 5b13dcc..419edbd 100644 --- a/pass-otp.bash.completion +++ b/pass-otp.bash.completion @@ -20,7 +20,7 @@ __password_store_extension_complete_otp() { ;; esac else - COMPREPLY+=($(compgen -W "insert append uri validate -h --help -c --clip" -- ${cur})) + COMPREPLY+=($(compgen -W "insert append uri validate -h --help -c --clip -q --quiet" -- ${cur})) _pass_complete_entries 1 fi } diff --git a/test/code.t b/test/code.t index 39310fb..19b4754 100755 --- a/test/code.t +++ b/test/code.t @@ -30,6 +30,17 @@ test_expect_success 'Generates HOTP code and increments counter' ' [[ $("$PASS" otp uri passfile) == "$inc" ]] ' +test_expect_success 'Generates HOTP code quietly' ' + uri="otpauth://hotp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&counter=10&issuer=Example" + inc="otpauth://hotp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&counter=11&issuer=Example" + + test_pass_git_init && + "$PASS" otp insert passfile <<< "$uri" && + code=$("$PASS" otp -q passfile) && + [[ ${#code} -eq 6 ]] && + [[ $("$PASS" otp uri passfile) == "$inc" ]] +' + test_expect_success 'HOTP counter increments and preserves multiline contents' ' uri="otpauth://hotp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&counter=10&issuer=Example" inc="otpauth://hotp/Example:alice@google.com?secret=JBSWY3DPEHPK3PXP&counter=11&issuer=Example" diff --git a/test/setup.sh b/test/setup.sh index 5fd7173..4029530 100644 --- a/test/setup.sh +++ b/test/setup.sh @@ -72,3 +72,8 @@ test_pass_init() { rm -rf "$PASSWORD_STORE_DIR" "$PASS" init "${KEY[@]}" } + +test_pass_git_init() { + rm -rf "$PASSWORD_STORE_DIR" + "$PASS" init "${KEY[@]}" && "$PASS" git init +} |