From 99419824e12ccfa082967248df356e15f456e8cd Mon Sep 17 00:00:00 2001 From: Martin Kletzander Date: Fri, 22 Mar 2019 12:33:29 +0100 Subject: Add support for quiet output of otp code command When using this option the output of `pass otp -q ...` is predictable and can be further used without parsing even when the password store is a repository as well. This is useful, for example, when using rofi-pass. The patch is written in a way that other commands can optionally use the quiet option for otp_insert as well. --- otp.bash | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'otp.bash') diff --git a/otp.bash b/otp.bash index c62501a..5539a5b 100755 --- a/otp.bash +++ b/otp.bash @@ -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 -- cgit v1.2.3