~tardypad/dotfiles

ref: f47033d719f9276d652b3b5c5162543cd10dd514 dotfiles/files/configs/qutebrowser/userscripts/autofill-login -rwxr-xr-x 1.5 KiB
f47033d7 — Damien Tardy-Panis qutebrowser autofill userscripts use globbing URL pattern 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/bin/sh
# commands used:
# - pass

# Autofill username and password for known websites.
# Rely on focus being on username field and the password field being
# accessible via a Tab press.

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

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

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

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

# 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 ${QUTE_URL}"
fi

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

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

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

if [ -z "${USERNAME}" ]; then
  USERNAME="$( echo "${SECRETS}" | sed -n 's/^email: \(.*\)/\1/p' )"
fi

PASSWORD="$( echo "${SECRETS}" | sed 1q )"

# escape all characters sent via fake-key command
{
  echo "insert-text -- ${USERNAME}"
  sleep 0.1
  echo 'fake-key <Tab>'
  sleep 0.1
  echo "insert-text -- ${PASSWORD}"
  echo 'mode-enter insert'
} >> "${QUTE_FIFO}"