Another option (if you don't use modern slow fat buggy version of Windows) would be to add start-ssh-agent.cmd
to startup and make it universal for all shells. This can be done by placing it f.ex. in your .ssh dir, making symlink to startup folder (with minimized run option) and applying the following patch to it:
--- "C:\\Program Files\\Git\\cmd\\start-ssh-agent.cmd" 2023-06-01 16:34:16.000000000 +0300
+++ start-ssh-agent.cmd 2023-08-09 00:31:44.304425700 +0300
@@ -25,6 +25,7 @@
@FOR %%s IN ("!SSH_AGENT!") DO @SET BIN_DIR=%%~dps
@FOR %%s in ("!BIN_DIR!") DO @SET BIN_DIR=!BIN_DIR:~0,-1!
@FOR /D %%s in ("!BIN_DIR!\ssh-add.exe") DO @SET SSH_ADD=%%~s
+ @FOR /D %%s in ("!BIN_DIR!\cygpath.exe") DO @SET CYGPATH=%%~s
@IF NOT EXIST "!SSH_ADD!" @GOTO ssh-agent-done
@REM Check if the agent is running
@FOR /f "tokens=1-2" %%a IN ('tasklist /fi "imagename eq ssh-agent.exe"') DO @(
@@ -77,9 +78,11 @@
:failure
@ENDLOCAL & @SET "SSH_AUTH_SOCK=%SSH_AUTH_SOCK%" ^
- & @SET "SSH_AGENT_PID=%SSH_AGENT_PID%"
+ & @SET "SSH_AGENT_PID=%SSH_AGENT_PID%" ^
+ & @SET "CYGPATH=%CYGPATH%"
-@ECHO %cmdcmdline% | @FINDSTR /l "\"\"" >NUL
-@IF NOT ERRORLEVEL 1 @(
- @CALL cmd %*
+@for /f %%c in ('"%CYGPATH%" -m %SSH_AUTH_SOCK%') do @(
+ @setx SSH_AUTH_SOCK "%%c" > nul
+ @set "SSH_AUTH_SOCK=%%c"
)
+@setx SSH_AGENT_PID %SSH_AGENT_PID% > nul
Thus you will get SSH_AUTH_SOCK in every shell usable. To the bottom of that file you can add any of your ssh-add
commands.