-
Notifications
You must be signed in to change notification settings - Fork 0
/
get-otp.in
32 lines (27 loc) · 719 Bytes
/
get-otp.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/sh
file="${OTP_ACCOUNTS:-$HOME/.local/share/otp_accounts}"
json="$(@PREFIX@/bin/cbc-file unlock "$file")"
[ -z "$json" ] && exit 1
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
label="$(printf %s "$json" |
jq '.[].label' 2>/dev/null |
$finder ${1:+-q "$1"}
)"
[ -z "$label" ] && exit 1
secret="$(printf %s "$json" |
jq --raw-output ".[] | select (.label | contains($label)) | .secret"
)"
[ -z "$secret" ] && exit 1
token="$(oathtool --totp -b -d 6 "$secret")"
printf %s "$token"
if [ "$WAYLAND_DISPLAY" ] && command -v wl-copy >/dev/null; then
printf %s "$token" | wl-copy
fi