#if (! -d $HOME/tmp ) mkdir $HOME/tmp
set agent = "$HOME/.ssh/ssh-agent-$USER"
if ($?SSH_AUTH_SOCK) then
    if (! -S $SSH_AUTH_SOCK) unsetenv SSH_AUTH_SOCK
endif
if ($?SSH_AUTH_SOCK) then
    if ($SSH_AUTH_SOCK =~ /tmp/*/agent.[0-9]*) then
         ln -snf "$SSH_AUTH_SOCK" $agent && setenv SSH_AUTH_SOCK $agent
    endif
    else if (-S $agent) then
         setenv SSH_AUTH_SOCK $agent
    else
         echo "no ssh-agent"
endif
if (-S $agent) then
  #echo "setenv SSH_AUTH_SOCK $agent" >>! ~/.ssh-agent
endif

unset agent
