Skip to content

Instantly share code, notes, and snippets.

@cristovaov
Last active September 17, 2024 08:21
Show Gist options
  • Save cristovaov/120abe29fd2aee2ba6b2f71eefbec594 to your computer and use it in GitHub Desktop.
Save cristovaov/120abe29fd2aee2ba6b2f71eefbec594 to your computer and use it in GitHub Desktop.
Launch ssh agent on bash startup on Windows for CMDR/Git Bash
# Start the ssh-agent
SSH_ENV=${HOME}/.ssh/agent.env
function start_agent {
echo "Initializing new SSH agent..."
# Spawning the ssh-agent
/usr/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
echo "Succeeded"
chmod 600 "${SSH_ENV}"
. "${SSH_ENV}" > /dev/null
/usr/bin/ssh-add
}
if [ -f "${SSH_ENV}" ]; then
. "${SSH_ENV}" > /dev/null
kill -0 "${SSH_AGENT_PID}" 2>/dev/null || {
start_agent;
}
else
start_agent;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment