summaryrefslogtreecommitdiff
path: root/zsh/functions/op-ssh-add
diff options
context:
space:
mode:
authorGrégoire Duchêne <gduchene@awhk.org>2020-09-06 10:31:27 +0100
committerGrégoire Duchêne <gduchene@awhk.org>2020-09-06 10:38:36 +0100
commit72973b0fc01f0adb7b4dadddd7e85496898e6fb5 (patch)
tree08424d85008546e9ee2ec221161455c55266f883 /zsh/functions/op-ssh-add
parentbad0d87c2888b023cca7cd180e63b514e68b8e92 (diff)
zsh: Add op-ssh-add function
op-ssh-add is a small wrapper around ssh-add that retrieves the SSH private key password from 1Password before passing it to ssh-add.
Diffstat (limited to 'zsh/functions/op-ssh-add')
-rw-r--r--zsh/functions/op-ssh-add28
1 files changed, 28 insertions, 0 deletions
diff --git a/zsh/functions/op-ssh-add b/zsh/functions/op-ssh-add
new file mode 100644
index 0000000..d64efd9
--- /dev/null
+++ b/zsh/functions/op-ssh-add
@@ -0,0 +1,28 @@
+# -*- mode: sh -*-
+
+if [[ ${@[1]} =~ '-[DdKLlTXx]' ]]; then
+ $(which -p ssh-add) $@
+ return $?
+fi
+
+local prv pub
+for prv (${@[-1]} ~/.ssh/id_{ecdsa,ed25519}{,_sk}); do
+ if [[ -f ${prv}.pub ]]; then
+ pub=${prv}.pub
+ break
+ fi
+done
+
+if [[ -z ${pub} ]]; then
+ $(which -p ssh-add) $@
+ return $?
+fi
+
+zmodload zsh/zpty
+zpty ssh $(which -p ssh-add) $@
+zpty -w ssh $(op get item \
+ $(cut -d' ' -f3 ${pub}) \
+ --fields password \
+ --session $(op signin --raw))
+zpty -r ssh
+zpty -d ssh