bashrc, bash_aliases: in cygwin, only launch ssh-agent when the first "ssh" command is executed

This commit is contained in:
Josh Holtrop 2014-03-19 09:20:39 -04:00
parent 034e52399b
commit ab87b07e83
2 changed files with 32 additions and 20 deletions

View File

@ -267,6 +267,7 @@ function mark()
########################################################################### ###########################################################################
if [[ -e /bin/cygwin1.dll ]]; then if [[ -e /bin/cygwin1.dll ]]; then
alias ip="ipconfig | grep -E 'IP(v4)? Address' | sed -e 's/.*: //'" alias ip="ipconfig | grep -E 'IP(v4)? Address' | sed -e 's/.*: //'"
function cs function cs
{ {
while [[ "$1" != "" ]] while [[ "$1" != "" ]]
@ -281,6 +282,7 @@ if [[ -e /bin/cygwin1.dll ]]; then
shift shift
done done
} }
function winpython function winpython
{ {
local winpython=/c/Python27/python.exe local winpython=/c/Python27/python.exe
@ -290,7 +292,34 @@ if [[ -e /bin/cygwin1.dll ]]; then
${winpython} "$@" ${winpython} "$@"
fi fi
} }
winpath="$(echo $PATH | sed -e 's/:/\n/g' | grep cygdrive | tr '\n' ':' | sed -e 's/:*$//')" winpath="$(echo $PATH | sed -e 's/:/\n/g' | grep cygdrive | tr '\n' ':' | sed -e 's/:*$//')"
function ssh_agent_start
{
# cygwin ssh-agent support, from
# http://www.webweavertech.com/ovidiu/weblog/archives/000326.html
export SSH_AUTH_SOCK=/tmp/.ssh_socket
ssh-add -l >/dev/null 2>&1
if [ $? = 2 ]; then
# exit status 2 means we couldn't connect to ssh-agent,
# so let's start one now
rm -f $SSH_AUTH_SOCK
ssh-agent -a $SSH_AUTH_SOCK >/tmp/.ssh-script
. /tmp/.ssh-script
echo $SSH_AGENT_PID >/tmp/.ssh-agent-pid
ssh-add ~/.ssh/JoshHoltropGentex
fi
}
function ssh_agent_stop
{
pid=$(cat /tmp/.ssh-agent-pid)
kill $pid
}
fi fi
# source any machine-local aliases # source any machine-local aliases

23
bashrc
View File

@ -7,27 +7,10 @@ if [ -f "${HOME}/.bash_aliases" ]; then
fi fi
if [ -e /bin/cygwin1.dll ]; then if [ -e /bin/cygwin1.dll ]; then
# cygwin ssh-agent support, from function ssh
# http://www.webweavertech.com/ovidiu/weblog/archives/000326.html
export SSH_AUTH_SOCK=/tmp/.ssh_socket
ssh-add -l >/dev/null 2>&1
if [ $? = 2 ]; then
# exit status 2 means we couldn't connect to ssh-agent,
# so let's start one now
rm -f $SSH_AUTH_SOCK
ssh-agent -a $SSH_AUTH_SOCK >/tmp/.ssh-script
. /tmp/.ssh-script
echo $SSH_AGENT_PID >/tmp/.ssh-agent-pid
ssh-add ~/.ssh/josh-walter
fi
function kill-agent
{ {
pid=$(cat /tmp/.ssh-agent-pid) ssh_agent_start
kill $pid command ssh "$@"
} }
# for scons # for scons