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
|
|
|
|
2021-10-24 21:13:28 -05:00
|
|
|
finder=
|
|
|
|
if command -v ef >/dev/null; then
|
|
|
|
finder="ef -c -1"
|
|
|
|
elif command -v fzf >/dev/null; then
|
|
|
|
finder="fzf --cycle -1"
|
|
|
|
else
|
|
|
|
echo "couldn't find finder" >&2
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2020-10-08 22:55:06 -05:00
|
|
|
label="$(printf %s "$json" |
|
|
|
|
jq '.[].label' 2>/dev/null |
|
2021-10-24 21:13:28 -05:00
|
|
|
$finder ${1:+-q "$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
|