3 rem Enable extensions, the `verify other 2>nul` is a trick from the setlocal help
5 setlocal EnableDelayedExpansion
7 echo Unable to enable extensions
11 rem Start the ssh-agent if needed by git
12 for %%i in
("git.exe") do set GIT
=%%~$
PATH:i
14 rem Get the ssh
-agent executable
15 for %%i in
("ssh-agent.exe") do set SSH_AGENT
=%%~$
PATH:i
16 if not exist "%SSH_AGENT%" (
17 for %%s in
("%GIT%") do set GIT_DIR
=%%~dps
18 for %%s in
("!GIT_DIR!") do set GIT_DIR
=!GIT_DIR
:~
0,-1!
19 for %%s in
("!GIT_DIR!") do set GIT_ROOT
=%%~dps
20 for %%s in
("!GIT_ROOT!") do set GIT_ROOT
=!GIT_ROOT
:~
0,-1!
21 for /D
%%s in
("!GIT_ROOT!\bin\ssh-agent.exe") do set SSH_AGENT
=%%~s
22 if not exist "!SSH_AGENT!" (
26 rem Get the ssh
-add executable
27 for %%s in
("!SSH_AGENT!") do set BIN_DIR
=%%~dps
28 for %%s in
("!BIN_DIR!") do set BIN_DIR
=!BIN_DIR
:~
0,-1!
29 for /D
%%s in
("!BIN_DIR!\ssh-add.exe") do set SSH_ADD
=%%~s
30 if not exist "!SSH_ADD!" (
33 rem Check
if the agent is running
34 for /f
"tokens=1-2" %%a in
('tasklist /fi "imagename eq ssh-agent.exe"') do (
35 echo %%b | findstr
/r
/c
:"[0-9][0-9]*" > nul
36 if "!errorlevel!" == "0" (
40 rem Connect up the current ssh
-agent
41 if [!SSH_AGENT_PID
!] == [] (
42 echo Removing old ssh
-agent sockets
43 for /d
%%d in
(%TEMP%\ssh
-??????
*) do rmdir /s
/q
%%d
45 echo Found ssh
-agent at
!SSH_AGENT_PID
!
46 for /d
%%d in
(%TEMP%\ssh
-??????
*) do (
47 for %%f in
(%%d
\agent.
*) do (
49 set SSH_AUTH_SOCK
=!SSH_AUTH_SOCK
:%TEMP%=/tmp
!
50 set SSH_AUTH_SOCK
=!SSH_AUTH_SOCK
:\
=/!
53 if not [!SSH_AUTH_SOCK
!] == [] (
54 echo Found ssh
-agent socket at
!SSH_AUTH_SOCK
!
56 echo Failed to
find ssh
-agent socket
60 rem See
if we have the key
61 "!SSH_ADD!" 1>nul
2>nul
62 set result
=!ERRORLEVEL!
63 if not !result
! == 0 (
65 echo|
set /p
=Starting ssh
-agent
:
66 for /f
"tokens=1-2 delims==;" %%a in
('"!SSH_AGENT!"') do (
73 set "HOME=%USERPROFILE%"
82 endlocal & set "SSH_AUTH_SOCK=%SSH_AUTH_SOCK%" ^
83 & set "SSH_AGENT_PID=%SSH_AGENT_PID%"
85 echo %cmdcmdline% | findstr
/l
"\"\"" >nul