Add coffin automation to pass-pick

This commit is contained in:
Marty Oehme 2021-12-18 10:34:07 +01:00
parent bd37843102
commit 8b3b49275c
Signed by: Marty
GPG key ID: B7538B8F50A1C800

View file

@ -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