Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@biinari
Created December 18, 2017 16:19
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save biinari/e5611220f90258552cd85032c9c09021 to your computer and use it in GitHub Desktop.
Save biinari/e5611220f90258552cd85032c9c09021 to your computer and use it in GitHub Desktop.
LastPass lpass backend to password_fill
#!/bin/sh
# Optional accompaniment to password_fill_rc (in case no existing graphical password askpass for lpass to use)
# put in ~/.config/qutebrowse/lpass_askpass_zenity
# and enable in password_fill_rc with need_askpass=1
zenity --title "lpass $*" --password
#!/bin/bash
#MENU_COMMAND=( choose_entry_zenity_radio )
# shellcheck disable=SC2034
MENU_COMMAND=( choose_entry_rofi )
choose_entry() {
choose_entry_rofi
}
# Set to 1 to use zenity to prompt for password. This will need accompanying
# executable shell script lpass_askpass_zenity to show a password prompt window
need_askpass=0
lpass_backend() {
init() {
if ! which lpass ; then
die "lpass command not installed"
fi
if ! lpass status -q ; then
local response
local user
local trust
local trust_arg=""
response=$(zenity --title 'qutebrowser LastPass login' \
--text 'Login to LastPass' \
--forms \
--add-entry='Username:' \
--add-entry='Trust? (y|N):')
user="${response%%|*}"
trust="$(echo "${response#*|}" | tr '[:upper:]' '[:lower:]')"
case $trust in
y|yes)
trust_arg='--trust'
;;
esac
if [ "$need_askpass" -eq 1 ] ; then
LPASS_ASKPASS="${QUTE_CONFIG_DIR}/lpass_askpass_zenity" lpass login ${trust_arg} "${user}"
else
lpass login ${trust_arg} "${user}"
fi
fi
}
query_entries() {
msg "Loading entries from lpass..."
local domain="$1"
local escaped_domain
local id
# shellcheck disable=SC2001
escaped_domain=$(echo "$domain" | sed 's/\(['\''".|?+[{}()]\|\]\)/\\\1/g')
while read -r line ; do
if echo "$line" | grep -q -iE "\\|url:https?://([^/?#]+\\.)*${escaped_domain}" ; then
id="${line%%|url:*}"
files+=("${id}")
fi
done < <(lpass ls --format="%/as%/ag%an|url:%al" 2>&1)
}
open_entry() {
local id="$1"
# shellcheck disable=SC2034
username="$(lpass show -u "$id")"
# shellcheck disable=SC2034
password="$(lpass show -p "$id")"
}
}
lpass_backend
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment