diff --git a/vendor/lib/start-ssh-agent.sh b/vendor/lib/start-ssh-agent.sh new file mode 100644 index 0000000..a359ae0 --- /dev/null +++ b/vendor/lib/start-ssh-agent.sh @@ -0,0 +1,22 @@ +# Copied from https://help.github.com/articles/working-with-ssh-key-passphrases +env=~/.ssh/agent.env + +agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; } + +agent_start () { + (umask 077; ssh-agent >| "$env") + . "$env" >| /dev/null ; } + +agent_load_env + +# agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running +agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?) + +if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then + agent_start + ssh-add +elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then + ssh-add +fi + +unset env \ No newline at end of file diff --git a/vendor/user_profile.sh.default b/vendor/user_profile.sh.default index 2e423c0..4d55ecc 100644 --- a/vendor/user_profile.sh.default +++ b/vendor/user_profile.sh.default @@ -3,30 +3,5 @@ # To add a new vendor to the path, do something like: # export PATH=${CMDER_ROOT}/vendor/whatever:${PATH} -function launch_ssh_agent { - # Copied from (https://help.github.com/articles/working-with-ssh-key-passphrases) - env=~/.ssh/agent.env - - agent_load_env () { test -f "$env" && . "$env" >| /dev/null ; } - - agent_start () { - (umask 077; ssh-agent >| "$env") - . "$env" >| /dev/null ; } - - agent_load_env - - # agent_run_state: 0=agent running w/ key; 1=agent w/o key; 2= agent not running - agent_run_state=$(ssh-add -l >| /dev/null 2>&1; echo $?) - - if [ ! "$SSH_AUTH_SOCK" ] || [ $agent_run_state = 2 ]; then - agent_start - ssh-add - elif [ "$SSH_AUTH_SOCK" ] && [ $agent_run_state = 1 ]; then - ssh-add - fi - - unset env -} - -# Run ssh-agent automatically when you open your first bash terminal -# launch_ssh_agent \ No newline at end of file +# Uncomment this to have the ssh agent load with the first bash terminal +# . "${CMDER_ROOT}/vendor/lib/start-ssh-agent.sh" \ No newline at end of file