2020-10-08 16:14:27 -05:00
|
|
|
#!/bin/sh
|
|
|
|
file="${OTP_ACCOUNTS:-$HOME/.local/share/otp_accounts}"
|
2020-10-08 23:13:32 -05:00
|
|
|
json="$(@PREFIX@/bin/cbc-file unlock "$file")"
|
2020-10-08 22:55:06 -05:00
|
|
|
[ -z "$json" ] && exit 1
|
2020-10-08 16:21:15 -05:00
|
|
|
|
2020-10-08 22:55:06 -05:00
|
|
|
label="$(printf %s "$json" |
|
|
|
|
jq '.[].label' 2>/dev/null |
|
2020-10-08 16:14:27 -05:00
|
|
|
fzf --cycle -1 ${1:+--query "$1"}
|
2020-10-08 22:55:06 -05:00
|
|
|
)"
|
2020-10-08 16:21:15 -05:00
|
|
|
[ -z "$label" ] && exit 1
|
|
|
|
|
2020-10-08 16:14:27 -05:00
|
|
|
secret="$(printf %s "$json" |
|
|
|
|
jq --raw-output ".[] | select (.label | contains($label)) | .secret"
|
|
|
|
)"
|
2020-10-08 16:21:15 -05:00
|
|
|
[ -z "$secret" ] && exit 1
|
|
|
|
|
2020-10-08 16:14:27 -05:00
|
|
|
token="$(oathtool --totp -b -d 6 "$secret")"
|
2020-10-08 16:21:15 -05:00
|
|
|
printf %s "$token"
|
2020-10-08 16:14:27 -05:00
|
|
|
|
2020-10-08 16:21:15 -05:00
|
|
|
if [ "$WAYLAND_DISPLAY" ] && command -v wl-copy >/dev/null; then
|
|
|
|
printf %s "$token" | wl-copy
|
2020-10-08 16:14:27 -05:00
|
|
|
fi
|