etc/my-rofi-pass

63 lines
1.1 KiB
Plaintext
Raw Permalink Normal View History

2020-11-26 17:48:20 +01:00
#!/usr/bin/env bash
set -eo pipefail
root="$HOME/.password-store"
list_accounts() {
(cd "$root" && find -L . -name "*.gpg" | sed 's,^\./,,;s/\.gpg$//' | sort -n)
}
list_accounts_beginning_with_blank_page() {
yes '' | head -n50
list_accounts
}
do_type() {
2022-05-02 18:55:32 +02:00
if [ -n "$WAYLAND_DISPLAY" ]; then
echo -n "$1" | wtype -s 100 -d 50 -
else
echo -n "$1" | xdotool type --delay=12 --file=-
fi
2020-11-26 17:48:20 +01:00
}
get_passwd() {
pass "$1" | head -n1
}
get_otp() {
pass otp "$1"
}
get_field() {
pass "$1" | grep "^$2: " | sed "s/$2: //"
}
account="$(list_accounts_beginning_with_blank_page | rofi -dmenu -p 'my-rofi-pass')"
test -n "$account" || exit
choices='password
username
url
otp'
choice="$(echo -n "$choices" | rofi -dmenu -p "$account")"
case "$choice" in
password)
passwd="$(get_passwd "$account")"
do_type "$passwd"
;;
username)
username="$(get_field "$account" username)"
do_type "$username"
;;
url)
url="$(get_field "$account" url)"
do_type "$url"
;;
otp)
otp="$(get_otp "$account")"
do_type "$otp"
;;
esac