Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ Generate a 2FA code using this token:
```
$ pass otp totp-secret
698816
Expires in 26 seconds
```

Display a QR code for an OTP token:
Expand Down
6 changes: 5 additions & 1 deletion otp.bash
Original file line number Diff line number Diff line change
Expand Up @@ -334,9 +334,11 @@ cmd_otp_code() {
local cmd
case "$otp_type" in
totp)
curr_time=$(date +%s)
totp_time_remaining=$((30 - (curr_time % 30)))
cmd="$OATH -b --totp"
[[ -n "$otp_algorithm" ]] && cmd+=$(echo "=${otp_algorithm}"|tr "[:upper:]" "[:lower:]")
[[ -n "$otp_period" ]] && cmd+=" --time-step-size=$otp_period"s
[[ -n "$otp_period" ]] && cmd+=" --time-step-size=$otp_period"s && totp_time_remaining=$((otp_period - (curr_time % otp_period)))
[[ -n "$otp_digits" ]] && cmd+=" --digits=$otp_digits"
cmd+=" $otp_secret"
;;
Expand Down Expand Up @@ -369,8 +371,10 @@ cmd_otp_code() {

if [[ $clip -ne 0 ]]; then
clip "$out" "OTP code for $path"
[[ -n "$totp_time_remaining" ]] && echo "Expires in $totp_time_remaining seconds"
else
echo "$out"
[[ -n "$totp_time_remaining" ]] && echo "Expires in $totp_time_remaining seconds"
fi
}

Expand Down
2 changes: 1 addition & 1 deletion test/code.t
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ test_expect_success 'Generates TOTP code' '

test_pass_init &&
"$PASS" otp insert passfile <<< "$uri" &&
code=$("$PASS" otp passfile) &&
code=$("$PASS" otp passfile | head -n 1) &&
[[ ${#code} -eq 6 ]]
'

Expand Down