From 534e493d7e841cf269fa7f17e382790271d111b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20Dudr?= Date: Thu, 31 Oct 2024 15:31:34 +0100 Subject: [PATCH] qute: gopass filler --- .../userscripts/executable_gopass-fill | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 dot_config/private_qutebrowser/userscripts/executable_gopass-fill diff --git a/dot_config/private_qutebrowser/userscripts/executable_gopass-fill b/dot_config/private_qutebrowser/userscripts/executable_gopass-fill new file mode 100644 index 0000000..7e7409c --- /dev/null +++ b/dot_config/private_qutebrowser/userscripts/executable_gopass-fill @@ -0,0 +1,47 @@ +#!/bin/bash + +set -x + +log() { + # echo "$@" >&2 + notify-send -t 1000 "Gopass form filler" "$*" +} + +qute-command() { + echo "$@" >> "$QUTE_FIFO" +} + +send-key() { + qute-command fake-key "$@" +} + +insert-text() { + qute-command insert-text "$@" +} + +domain="$(echo "$QUTE_URL" | sed -E 's|^https?://||;s|/.*||')" + +mapfile -t secrets < <(gopass find "$domain") + +mode=${1:-"login-password"} + +if (( ${#secrets[@]} > 1 )) +then + secret="$(printf "%s\n" "${secrets[@]}" | rofi -dmenu)" +elif (( ${#secrets[@]} < 1 )) +then + log "No secret found!" + exit 0 +else + secret="${secrets[0]}" +fi + +if [[ -z "$secret" ]] +then + exit 0 +fi + +if [[ "$mode" = *login* ]] ; then insert-text "$(gopass show -o "$secret" login)" && sleep 0.1 ; fi +if [[ "$mode" = "login-password" ]] ; then send-key "" ; fi +if [[ "$mode" = *password* ]] ; then insert-text "$(gopass show -o "$secret")" ; fi +if [[ "$mode" = "otp" ]] ; then insert-text "$(gopass otp -o "$secret")" ; fi