diff --git a/profile b/profile index 1b0e61f..d155ff7 100644 --- a/profile +++ b/profile @@ -12,7 +12,7 @@ if [ -n "$BASH_VERSION" ]; then # include .bashrc if it exists if [ -f "$HOME/.bashrc" ]; then - . "$HOME/.bashrc" + . "$HOME/.bashrc" fi fi @@ -31,3 +31,8 @@ if [ -d "$HOME/.scripts" ] ; then PATH="$HOME/.scripts:$PATH" fi +# Enable Ssh-Agent +if [ -n "$BASH_VERSION" ]; then + . "$HOME/.scripts/ssh_session" +fi + diff --git a/scripts/ssh_session b/scripts/ssh_session new file mode 100755 index 0000000..c43e268 --- /dev/null +++ b/scripts/ssh_session @@ -0,0 +1,28 @@ +#!/bin/bash + +# +# setup ssh-agent +# + +SSH_ENV="$HOME/.ssh/environment" + +function start_agent { + echo "Initialising new 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; +} + +# Source SSH settings, if applicable + +if [ -f "${SSH_ENV}" ]; then + . "${SSH_ENV}" > /dev/null + ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || { + start_agent; + } +else + start_agent; +fi +