fix: make .zprofile SSH agent setup fail-safe
- Create ~/.ssh dir if missing before writing agent-environment - Suppress ssh-add errors (no keys yet is fine) - Skip entire block if ssh-agent binary is not installed Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -2,20 +2,25 @@ SSH_ENV="$HOME/.ssh/agent-environment"
|
||||
|
||||
function start_agent {
|
||||
echo "Initialising new SSH agent..."
|
||||
mkdir -p "$HOME/.ssh"
|
||||
chmod 700 "$HOME/.ssh"
|
||||
/usr/bin/ssh-agent | sed 's/^echo/#echo/' >"$SSH_ENV"
|
||||
echo succeeded
|
||||
chmod 600 "$SSH_ENV"
|
||||
. "$SSH_ENV" >/dev/null
|
||||
/usr/bin/ssh-add;
|
||||
/usr/bin/ssh-add 2>/dev/null || true
|
||||
}
|
||||
|
||||
# Source SSH settings, if applicable
|
||||
# Source SSH settings, if applicable — skip entirely if ssh-agent is not available
|
||||
if ! command -v ssh-agent >/dev/null 2>&1; then
|
||||
return 0
|
||||
fi
|
||||
|
||||
if [ -f "$SSH_ENV" ]; then
|
||||
. "$SSH_ENV" >/dev/null
|
||||
#ps $SSH_AGENT_PID doesn't work under Cygwin
|
||||
ps -ef | grep $SSH_AGENT_PID | grep ssh-agent$ >/dev/null || {
|
||||
start_agent
|
||||
}
|
||||
else
|
||||
start_agent
|
||||
fi
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user