diff options
| author | Grégoire Duchêne <gduchene@awhk.org> | 2020-09-06 10:31:27 +0100 |
|---|---|---|
| committer | Grégoire Duchêne <gduchene@awhk.org> | 2020-09-06 10:38:36 +0100 |
| commit | 72973b0fc01f0adb7b4dadddd7e85496898e6fb5 (patch) | |
| tree | 08424d85008546e9ee2ec221161455c55266f883 /zsh/functions | |
| parent | bad0d87c2888b023cca7cd180e63b514e68b8e92 (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')
| -rw-r--r-- | zsh/functions/_op-ssh-add | 3 | ||||
| -rw-r--r-- | zsh/functions/op-ssh-add | 28 |
2 files changed, 31 insertions, 0 deletions
diff --git a/zsh/functions/_op-ssh-add b/zsh/functions/_op-ssh-add new file mode 100644 index 0000000..2c2183e --- /dev/null +++ b/zsh/functions/_op-ssh-add @@ -0,0 +1,3 @@ +#compdef op-ssh-add=ssh-add + +_ssh $@ 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 |
