Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

calling @call start-ssh-agent results in a few ugly lines printed #314

Closed
jankatins opened this issue Aug 25, 2015 · 4 comments
Closed

calling @call start-ssh-agent results in a few ugly lines printed #314

jankatins opened this issue Aug 25, 2015 · 4 comments
Labels

Comments

@jankatins
Copy link

I use cmder and have @call start-ssh-agent in my init.bat. Unfortunately this results in a few ugly lines printed on startup:


(                                                                                                 


)                                                                                                 
Removing old ssh-agent sockets                                                                    
Starting ssh-agent:                                                                               
()                                                                                                

()                                                                                                

()                                                                                                
 done                                                                                             
Enter passphrase for /c/Users/.../.ssh/id_rsa:                                     
Identity added: /c/Users/.../.ssh/id_rsa (/c/Users/.../.ssh/id_rsa)                       


I added a @ in front of all opening parentheses (like ... DO @() and the prints are now gone.

Removing old ssh-agent sockets
Starting ssh-agent:  done
Enter passphrase for /c/Users/.../.ssh/id_rsa:
Identity added: /c/Users/.../.ssh/id_rsa (/c/Users/.../.ssh/id_rsa)


[It has still two empty lines in the end but only one in each following start when I don't need to input my password...]

I couldn't find the place where this script is built from. I will happily make a PR for this...

--- "orig/start-ssh-agent.cmd"  2015-08-17 15:18:54.000000000 +0200
+++ "modified/start-ssh-agent.cmd"  2015-08-25 12:07:24.260835000 +0200
@@ -10,10 +10,10 @@

 @REM Start the ssh-agent if needed by git
 @FOR %%i IN ("git.exe") DO @SET GIT=%%~$PATH:i
-@IF EXIST "%GIT%" (
+@IF EXIST "%GIT%" @(
     @REM Get the ssh-agent executable
     @FOR %%i IN ("ssh-agent.exe") DO @SET SSH_AGENT=%%~$PATH:i
-    @IF NOT EXIST "%SSH_AGENT%" (
+    @IF NOT EXIST "%SSH_AGENT%" @(
         @FOR %%s IN ("%GIT%") DO @SET GIT_DIR=%%~dps
         @FOR %%s IN ("!GIT_DIR!") DO @SET GIT_DIR=!GIT_DIR:~0,-1!
         @FOR %%s IN ("!GIT_DIR!") DO @SET GIT_ROOT=%%~dps
@@ -27,38 +27,43 @@
     @FOR /D %%s in ("!BIN_DIR!\ssh-add.exe") DO @SET SSH_ADD=%%~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 (
+    @FOR /f "tokens=1-2" %%a IN ('tasklist /fi "imagename eq ssh-agent.exe"') DO @(
         @ECHO %%b | @FINDSTR /r /c:"[0-9][0-9]*" > NUL
-        @IF "!ERRORLEVEL!" == "0" @SET SSH_AGENT_PID=%%b
+        @IF "!ERRORLEVEL!" == "0" @(
+           @SET SSH_AGENT_PID=%%b
+       ) else @(
+           @REM Unset in the case a user kills the agent while a session is open
+           @SET SSH_AGENT_PID=
+       )
     )
     @REM Connect up the current ssh-agent
-    @IF [!SSH_AGENT_PID!] == [] (
+    @IF [!SSH_AGENT_PID!] == []  @(
         @ECHO Removing old ssh-agent sockets
         @FOR /d %%d IN (%TEMP%\ssh-??????*) DO @RMDIR /s /q %%d
-    ) ELSE (
+    ) ELSE  @(
         @ECHO Found ssh-agent at !SSH_AGENT_PID!
-        @FOR /d %%d IN (%TEMP%\ssh-??????*) DO (
-            @FOR %%f IN (%%d\agent.*) DO (
+        @FOR /d %%d IN (%TEMP%\ssh-??????*) DO @(
+            @FOR %%f IN (%%d\agent.*) DO @(
                 @SET SSH_AUTH_SOCK=%%f
                 @SET SSH_AUTH_SOCK=!SSH_AUTH_SOCK:%TEMP%=/tmp!
                 @SET SSH_AUTH_SOCK=!SSH_AUTH_SOCK:\=/!
             )
         )
-        @IF NOT [!SSH_AUTH_SOCK!] == [] (
+        @IF NOT [!SSH_AUTH_SOCK!] == [] @(
             @ECHO Found ssh-agent socket at !SSH_AUTH_SOCK!
         ) ELSE (
             @ECHO Failed to find ssh-agent socket
-            SET SSH_AGENT_PID=
+            @SET SSH_AGENT_PID=
         )
     )
     @REM See if we have the key
     @SET "HOME=%USERPROFILE%"
     @"!SSH_ADD!" -l 1>NUL 2>NUL
     @SET result=!ERRORLEVEL!
-    @IF NOT !result! == 0 (
-        @IF !result! == 2 (
+    @IF NOT !result! == 0 @(
+        @IF !result! == 2 @(
             @ECHO | @SET /p=Starting ssh-agent:
-            @FOR /f "tokens=1-2 delims==;" %%a IN ('"!SSH_AGENT!"') DO (
+            @FOR /f "tokens=1-2 delims==;" %%a IN ('"!SSH_AGENT!"') DO @(
                 @IF NOT [%%b] == [] @SET %%a=%%b
             )
             @ECHO. done
@@ -75,6 +80,6 @@
           & @SET "SSH_AGENT_PID=%SSH_AGENT_PID%"

 @ECHO %cmdcmdline% | @FINDSTR /l "\"\"" >NUL
-@IF NOT ERRORLEVEL 1 (
+@IF NOT ERRORLEVEL 1 @(
     @CALL cmd %*
 )
@dscho
Copy link
Member

dscho commented Aug 25, 2015

Thank you for your contribution! This almost looks like a proper Pull Request!

Would you maybe go the full nine yards, check out https://github.com/git-for-windows/MINGW-packages/, patch mingw-w64-git/start-ssh-agent.cmd (i.e. copy your version over it), then commit that with a nice commit message and open a real Pull Request?

Thanks!

@dscho dscho added the bug label Aug 25, 2015
@jankatins
Copy link
Author

Will do...

@jankatins
Copy link
Author

done in git-for-windows/MINGW-packages#14

@dscho
Copy link
Member

dscho commented Aug 25, 2015

Perfect, thank you!

@dscho dscho closed this as completed Aug 25, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants