Add sanity to pass-otp

This commit is contained in:
Daniel Flanagan 2020-09-17 11:31:40 -05:00
parent c63739cb19
commit 58c8387ddd
Signed by: lytedev
GPG key ID: 5B2020A0F9921EF4

View file

@ -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"