~tardypad/dotfiles

f47033d719f9276d652b3b5c5162543cd10dd514 — Damien Tardy-Panis a month ago 26d47f4
qutebrowser autofill userscripts use globbing URL pattern

To accommodate for mappings based on path and not only domain
M files/configs/qutebrowser/userscripts/autofill-login => files/configs/qutebrowser/userscripts/autofill-login +20 -7
@@ 6,7 6,7 @@
# Rely on focus being on username field and the password field being
# accessible via a Tab press.

DOMAINS_PASS_ID_FILE="${PASSWORD_STORE_DIR:-$HOME/.password-store}/domains_pass_id"
URLS_PASS_ID_FILE="${PASSWORD_STORE_DIR:-$HOME/.password-store}/urls_pass_id"

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


@@ 18,21 18,34 @@ exit_warning() {
  exit 0
}

if [ ! -f "${DOMAINS_PASS_ID_FILE}" ]; then
  exit_error 'Missing domains pass id file'
if [ ! -f "${URLS_PASS_ID_FILE}" ]; then
  exit_error 'Missing urls pass id file'
fi

DOMAIN="$( echo "${QUTE_URL}" | awk -F/ '{print $3}' )"
PASS_ID="$( grep "^${DOMAIN}	" "${DOMAINS_PASS_ID_FILE}" | cut -f2 )"
# remove protocol from URL
URL="$( echo "${QUTE_URL}" | cut -d/ -f3- )"

PASS_ID=

# get first matching pass id
# shellcheck disable=SC2254
while read -r LINE; do
  case "${URL}" in
    $( echo "${LINE}" | cut -f1 ))
      PASS_ID="$( echo "${LINE}" | cut -f2 )"
      break
      ;;
  esac
done < "${URLS_PASS_ID_FILE}"

if [ -z "${PASS_ID}" ]; then
  exit_warning "No existing credentials for ${DOMAIN}"
  exit_warning "No existing credentials for ${QUTE_URL}"
fi

SECRETS="$( pass "${PASS_ID}" )"

if [ -z "${SECRETS}" ]; then
  exit_error "Invalid pass identifier ${PASS_ID} for ${DOMAIN}"
  exit_error "Invalid pass identifier ${PASS_ID} for ${QUTE_URL}"
fi

USERNAME="$( echo "${SECRETS}" | sed -n 's/^username: \(.*\)/\1/p' )"

M files/configs/qutebrowser/userscripts/autofill-otp => files/configs/qutebrowser/userscripts/autofill-otp +20 -7
@@ 5,7 5,7 @@
# 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"
URLS_OTP_ID_FILE="${PASSWORD_STORE_DIR:-$HOME/.password-store}/urls_otp_id"

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


@@ 17,21 17,34 @@ exit_warning() {
  exit 0
}

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

DOMAIN="$( echo "${QUTE_URL}" | awk -F/ '{print $3}' )"
OTP_ID="$(grep "^${DOMAIN}	" "${DOMAINS_OTP_ID_FILE}" | cut -f2 )"
# remove protocol from URL
URL="$( echo "${QUTE_URL}" | cut -d/ -f3- )"

OTP_ID=

# get first matching otp id
# shellcheck disable=SC2254
while read -r LINE; do
  case "${URL}" in
    $( echo "${LINE}" | cut -f1 ))
      OTP_ID="$( echo "${LINE}" | cut -f2 )"
      break
      ;;
  esac
done < "${URLS_OTP_ID_FILE}"

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

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

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

{