mirror of https://github.com/ericonr/get-otp.git
23 lines
558 B
Bash
23 lines
558 B
Bash
#!/bin/sh
|
|
file="${OTP_ACCOUNTS:-$HOME/.local/share/otp_accounts}"
|
|
json="$(@PREFIX@/bin/cbc-file unlock "$file")"
|
|
[ -z "$json" ] && exit 1
|
|
|
|
label="$(printf %s "$json" |
|
|
jq '.[].label' 2>/dev/null |
|
|
fzf --cycle -1 ${1:+--query "$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
|