logo

dotfiles

My dotfiles, one branch per machine
commit: cffd44221e011ac881f698ba1b2c94483a389e19
parent: 3713b1c6cdf6337438d7ceb15337cdd5eccdd090
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Tue,  1 Oct 2019 08:46:08 +0200

.profile: correct ssh-start-agent, separate init to ssh-add-all

Diffstat:

M.profile27+++++++++++++++++++--------
1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/.profile b/.profile @@ -126,15 +126,26 @@ case $SHELL in esac # = helpers = +ssh-add-all() { + ssh-add $(find ~/.ssh -name 'id_*' -a \( \! -name '*.pub' \)) +} + ssh-start-agent() { - if [ $(ssh-add -l; echo ${?}) == '2' ]; then - rm -fr $SSH_AUTH_SOCK - eval $(ssh-agent -a ~/.ssh/agent.sock) - echo $SSH_AGENT_PID > ~/.ssh/agent.pid - ssh-add - else - echo 'SSH agent appear to be active' - fi + code="$(ssh-add -l; echo ${?})" + + case "${code}" in + 0) echo 'Managed to list keys, SSH agent appear to be active' ;; + 1) echo 'Failed to list keys' ;; + 2) + rm -fr "$SSH_AUTH_SOCK" + eval $(ssh-agent -a ~/.ssh/agent.sock) + echo "$SSH_AGENT_PID" > ~/.ssh/agent.pid + return 0 + ;; + *) echo 'Unknown return code: '${code} ;; + esac + + return 1 } ssh-tunnel() {