Move to Chezmoi
This commit is contained in:
parent
f216c4ff2c
commit
e3498e73b5
59 changed files with 499 additions and 2240 deletions
chezmoi/dot_zshrc.d
43
chezmoi/dot_zshrc.d/executable_ssh.zsh
Normal file
43
chezmoi/dot_zshrc.d/executable_ssh.zsh
Normal file
|
@ -0,0 +1,43 @@
|
|||
SSH_ENV_CACHE="$HOME/.ssh/environment-$SHORT_HOST"
|
||||
|
||||
function _start_agent() {
|
||||
if _check_ssh_agent_connectivity; then
|
||||
return
|
||||
fi
|
||||
|
||||
if [[ -r "$SSH_ENV_CACHE" ]]; then
|
||||
. $SSH_ENV_CACHE &> /dev/null
|
||||
if _check_ssh_agent_connectivity; then
|
||||
return
|
||||
fi
|
||||
fi
|
||||
|
||||
echo -n >! "$SSH_ENV_CACHE"
|
||||
chmod 600 "$SSH_ENV_CACHE"
|
||||
ssh-agent -s > "$SSH_ENV_CACHE"
|
||||
. "$SSH_ENV_CACHE" > /dev/null
|
||||
}
|
||||
|
||||
function _check_ssh_agent_connectivity() {
|
||||
ssh-add -l &> /dev/null
|
||||
if [[ $? -eq 2 ]]; then
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
function add_ssh_keys() {
|
||||
declare -a NEW_IDENTITIES
|
||||
|
||||
SSH_AGENT_IDENTITIES="$(ssh-add -l || true)"
|
||||
2>/dev/null for IDENTITY_FILE in ~/.ssh/id_*~*.pub; do
|
||||
if [[ "$SSH_AGENT_IDENTITIES" != *"$(ssh-keygen -lf "$IDENTITY_FILE")"* ]]; then
|
||||
NEW_IDENTITIES+=("$IDENTITY_FILE")
|
||||
fi
|
||||
done
|
||||
|
||||
if [[ ${#NEW_IDENTITIES} -gt 0 ]]; then
|
||||
ssh-add ${^NEW_IDENTITIES}
|
||||
fi
|
||||
}
|
||||
|
||||
_start_agent && add_ssh_keys
|
Loading…
Add table
Add a link
Reference in a new issue