dotfiles/bin/lp-ssh-add
2018-02-26 12:56:34 +01:00

23 lines
414 B
Bash
Executable file

#!/bin/bash
set -e
if [[ "$SSH_ASKPASS" == $0 ]]; then
exec lpass show --field Passphrase $_KEYID
fi
if [[ -z "$1" ]]; then
_key=$(lpass ls --color=never ssh | cut -d ' ' -f1 | fzf -1 -0)
exec $0 $_key
fi
_tmp=$(mktemp -d)
cd $_tmp
mkdir -p $(dirname $1)
ln -s /dev/stdin $1
function cleanup {
rm -rf $_tmp
}
trap cleanup EXIT
lpass show --field='Private Key' $1 | SSH_ASKPASS=$0 _KEYID=$1 ssh-add $1