summaryrefslogtreecommitdiff
path: root/zsh/functions
diff options
context:
space:
mode:
authorGrégoire Duchêne <gduchene@awhk.org>2021-03-14 11:13:52 +0000
committerGrégoire Duchêne <gduchene@awhk.org>2021-03-14 11:20:04 +0000
commit78c498391af5ba8b00706dfc2fd9ce6c9b0204f2 (patch)
tree1c31f546224e150bb28633c19df4585d0a098e49 /zsh/functions
parent5438197b6dc9ff171c9d7b2e6de3b21e7567cc45 (diff)
zsh/op-ssh-add: Trap cleanup code
Diffstat (limited to 'zsh/functions')
-rw-r--r--zsh/functions/op-ssh-add15
1 files changed, 12 insertions, 3 deletions
diff --git a/zsh/functions/op-ssh-add b/zsh/functions/op-ssh-add
index 646b7f7..90cff9a 100644
--- a/zsh/functions/op-ssh-add
+++ b/zsh/functions/op-ssh-add
@@ -34,13 +34,22 @@ local session=$(op signin --raw)
if [[ -z ${session} ]]; then
return 1
fi
+
zmodload zsh/zpty
zpty ssh $(which -p ssh-add) ${prv}
-zpty -w ssh $(op list items --session ${session} --tags SSH \
+
+_cleanup() {
+ zpty -d ssh
+ op signout --session $1
+ trap -
+ unfunction _cleanup
+}
+trap "_cleanup ${session}" EXIT HUP INT TERM
+
+zpty -w ssh $(trap -
+ op list items --session ${session} --tags SSH \
| op get item \
--fields fingerprint,password \
--session ${session} - \
| jq -jr "select(.fingerprint == \"${fp}\") | .password")
zpty -r ssh
-zpty -d ssh
-op signout --session ${session}