From 8b3b49275c0c8de62b49579ca014e76e9e090b87 Mon Sep 17 00:00:00 2001 From: Marty Oehme Date: Sat, 18 Dec 2021 10:34:07 +0100 Subject: [PATCH] Add coffin automation to pass-pick --- pass/.local/bin/pass-pick | 33 +++++++++++++++++++++++++++------ 1 file changed, 27 insertions(+), 6 deletions(-) diff --git a/pass/.local/bin/pass-pick b/pass/.local/bin/pass-pick index d494fdf..b6ca935 100755 --- a/pass/.local/bin/pass-pick +++ b/pass/.local/bin/pass-pick @@ -109,6 +109,9 @@ set_defaults() { AUTOFILL_CHAIN="${PP_AUTOENTRY_CHAIN:-$(get_config AUTOFILL_CHAIN 'username :tab password')}" AUTOFILL_DELAY="${PP_AUTOENTRY_DELAY:-$(get_config AUTOFILL_DELAY 30)}" PASS_USERNAME_FIELD="${PP_PASS_USERNAME_FIELD:-$(get_config PASS_USERNAME_FIELD 'username user login')}" + + PASS_COFFIN_OPEN_TIME="${PP_PASS_COFFIN_OPEN_TIME:-$(get_config PASS_COFFIN_OPEN_TIME 0)}" + PASS_COFFIN_LOCATION="${PP_PASS_COFFIN_LOCATION:-$(get_config PASS_COFFIN_LOCATION)}" } # exit on escape pressed @@ -311,6 +314,26 @@ entrymenu() { esac } +open_coffin() { + ## there's a closed coffin in our directory + if [ -f "${PASS_COFFIN_LOCATION:-${PASSWORD_STORE_DIR:-~/.password-store}/.coffin/coffin.tar.gpg}" ]; then + if [ "$PASS_COFFIN_OPEN_TIME" -eq 0 ]; then + coffin_should_close_instantly=true + pass open -t 1h # we still set a maximum time limit just to hedge against failures + else + pass open -t "${PASS_COFFIN_OPEN_TIME:-3h}" + fi + fi +} + +# make sure we remember to close the coffin if the program terminates +close_coffin() { + if [ "$coffin_should_close_instantly" = true ]; then + pass close + fi +} +trap close_coffin SIGINT SIGTERM ERR EXIT + main() { local autoentry_chain="${AUTOFILL_CHAIN}" local k_autofill="${KEY_AUTOFILL}" @@ -320,6 +343,8 @@ main() { local k_clip_pass="${KEY_CLIP_PASS}" local k_submenu="${KEY_ENTRY_OPEN}" + open_coffin + entry="$( list_passwords | _picker -kb-accept-entry "" \ @@ -338,29 +363,25 @@ main() { case "$exit_value" in "0" | "10") autofill "$entry" "$autoentry_chain" - exit 0 ;; "11") clip_username "$entry" - exit 0 ;; "12") clip_password "$entry" - exit ;; "13") autofill "$entry" "username" - exit ;; "14") autofill "$entry" "password" - exit ;; "15") entrymenu "$entry" - exit ;; esac + + exit 0 } set_defaults