From 58c8387dddd8faf51ec5dbcd082b356f44e80c44 Mon Sep 17 00:00:00 2001 From: Daniel Flanagan Date: Thu, 17 Sep 2020 11:31:40 -0500 Subject: [PATCH] Add sanity to pass-otp --- bin/pass-otp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/pass-otp b/bin/pass-otp index 2e01286..92f9a1d 100755 --- a/bin/pass-otp +++ b/bin/pass-otp @@ -5,5 +5,8 @@ key="$1"; shift args=("$@") -otp="$(pass "$key" | grep -Pi '^otp.*: ?.*$' | cut -d ':' -f 2 | sed 's/ //g')" +otp="$(set -e; pass "$key" 2>/dev/null | grep -Pi '^otp.*: ?.*$' | cut -d ':' -f 2 | sed 's/ //g')" +otp_status="$?" +[[ $otp_status != 0 ]] && { echo "pass command failed with exit code $otp_status"; exit 1; } +[[ -z $otp ]] && { echo "No OTP secret found for pass entry '$key'"; exit 2; } simple-otp "$otp"