~tardypad/dotfiles

ref: 26d47f47b8a70caec237e3812d53a3250f26bfe4 dotfiles/files/configs/qutebrowser/userscripts/autofill-otp -rwxr-xr-x 901 bytes
26d47f47 — Damien Tardy-Panis Update packages version in doc 3 months ago
                                                                                
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
33
34
35
36
37
38
39
40
#!/bin/sh
# commands used:
# - ykman

# Autofill OTP for known websites.
# Rely on focus being on OTP field

DOMAINS_OTP_ID_FILE="${PASSWORD_STORE_DIR:-$HOME/.password-store}/domains_otp_id"

exit_error() {
  echo "message-error 'autofill-otp: $1'" >> "${QUTE_FIFO}"
  exit 0
}

exit_warning() {
  echo "message-warning 'autofill-otp: $1'" >> "${QUTE_FIFO}"
  exit 0
}

if [ ! -f "${DOMAINS_OTP_ID_FILE}" ]; then
  exit_error 'Missing domains otp id file'
fi

DOMAIN="$( echo "${QUTE_URL}" | awk -F/ '{print $3}' )"
OTP_ID="$(grep "^${DOMAIN}	" "${DOMAINS_OTP_ID_FILE}" | cut -f2 )"

if [ -z "${OTP_ID}" ]; then
  exit_warning "No existing OTP for ${DOMAIN}"
fi

OTP_CODE="$( ykman oath accounts code -s "${OTP_ID}" )"

if [ -z "${OTP_CODE}" ]; then
  exit_error "Invalid OTP identifier ${OTP_ID} for ${DOMAIN}"
fi

{
  echo "insert-text -- ${OTP_CODE}"
  echo 'mode-enter insert'
} >> "${QUTE_FIFO}"