Fix condition to launch ssh-agent

This commit is contained in:
gardouille 2021-09-27 16:50:53 +02:00
parent c6efe15908
commit 8cea44ecc4
Signed by: gardouille
GPG Key ID: E759BAA22501AF32
1 changed files with 12 additions and 11 deletions

23
zshrc
View File

@ -323,18 +323,19 @@ alias josm="java -jar -Xmx2048M /opt/josm-tested.jar"
## 1. in zlogin (for a new shell)
## 2. with recossh alias to load a new ssh-agent
function load-ssh-agent() {
## If a ssh-key is available
## AND ssh-agent not launched
if find "${HOME}/.ssh" -maxdepth 1 -type f -iname "id_*" > /dev/null 2>&1 &&
! ps -x | grep -v grep | grep -Fq -- "ssh-agent -a ${SSH_AGENT_SOCK}"; then
### Remove any previous socket and environment files
rm --force -- "${SSH_AGENT_SOCK}" "${SSH_AGENT_ENV}"
### Start ssh-agent with a specified socket path
### AND store informations in a file
ssh-agent -a "${SSH_AGENT_SOCK}" > "${SSH_AGENT_ENV}"
# If a ssh-key is available
if find "${HOME}/.ssh" -maxdepth 1 -type f -iname "id_*" | grep -q -- .; then
## If ssh-agent is not already launched
if ! ps -x | grep -v grep | grep -Fq -- "ssh-agent -a ${SSH_AGENT_SOCK}"; then
### Remove any previous socket and environment files
rm --force -- "${SSH_AGENT_SOCK}" "${SSH_AGENT_ENV}"
### Start ssh-agent with a specified socket path
### AND store informations in a file
ssh-agent -a "${SSH_AGENT_SOCK}" > "${SSH_AGENT_ENV}"
fi
## Load content of ssh-agent environment file
source "${SSH_AGENT_ENV}"
fi
## Load content of ssh-agent environment file
source "${SSH_AGENT_ENV}"
}
# }}}
# Add ed25519 ssh-key to ssh-agent {{{