Advertisement
k0mZ

Untitled

Apr 8th, 2018
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.78 KB | None | 0 0
  1. @echo off
  2.  
  3. :: Init Script for cmd.exe
  4. :: Created as part of cmder project
  5.  
  6. :: !!! THIS FILE IS OVERWRITTEN WHEN CMDER IS UPDATED
  7. :: !!! Use "%CMDER_ROOT%\config\user-profile.cmd" to add your own startup commands
  8.  
  9. :: Set to > 0 for verbose output to aid in debugging.
  10. if not defined verbose-output ( set verbose-output=0 )
  11.  
  12. :: Find root dir
  13. if not defined CMDER_ROOT (
  14. if defined ConEmuDir (
  15. for /f "delims=" %%i in ("%ConEmuDir%\..\..") do set "CMDER_ROOT=%%~fi"
  16. ) else (
  17. for /f "delims=" %%i in ("%~dp0\..") do set "CMDER_ROOT=%%~fi"
  18. )
  19. )
  20.  
  21. :: Remove trailing '\'
  22. if "%CMDER_ROOT:~-1%" == "\" SET "CMDER_ROOT=%CMDER_ROOT:~0,-1%"
  23.  
  24. :: Pick right version of clink
  25. if "%PROCESSOR_ARCHITECTURE%"=="x86" (
  26. set architecture=86
  27. ) else (
  28. set architecture=64
  29. )
  30.  
  31. :: Tell the user about the clink config files...
  32. if not exist "%CMDER_ROOT%\config\settings" (
  33. echo Generating clink initial settings in "%CMDER_ROOT%\config\settings"
  34. echo Additional *.lua files in "%CMDER_ROOT%\config" are loaded on startup.
  35. )
  36.  
  37. :: Run clink
  38. "%CMDER_ROOT%\vendor\clink\clink_x%architecture%.exe" inject --quiet --profile "%CMDER_ROOT%\config" --scripts "%CMDER_ROOT%\vendor"
  39.  
  40. :: Prepare for git-for-windows
  41.  
  42. :: I do not even know, copypasted from their .bat
  43. set PLINK_PROTOCOL=ssh
  44. if not defined TERM set TERM=cygwin
  45.  
  46. :: The idea:
  47. :: * if the users points as to a specific git, use that
  48. :: * test if a git is in path and if yes, use that
  49. :: * last, use our vendored git
  50. :: also check that we have a recent enough version of git (e.g. test for GIT\cmd\git.exe)
  51. if defined GIT_INSTALL_ROOT (
  52. if exist "%GIT_INSTALL_ROOT%\cmd\git.exe" (goto :FOUND_GIT)
  53. )
  54.  
  55. :: check if git is in path...
  56. setlocal enabledelayedexpansion
  57. for /F "delims=" %%F in ('where git.exe 2^>nul') do @(
  58. pushd %%~dpF
  59. cd ..
  60. set "test_dir=!CD!"
  61. popd
  62. if exist "!test_dir!\cmd\git.exe" (
  63. set "GIT_INSTALL_ROOT=!test_dir!"
  64. set test_dir=
  65. goto :FOUND_GIT
  66. ) else (
  67. echo Found old git version in "!test_dir!", but not using...
  68. set test_dir=
  69. )
  70. )
  71.  
  72. :: our last hope: our own git...
  73. :VENDORED_GIT
  74. if exist "%CMDER_ROOT%\vendor\git-for-windows" (
  75. set "GIT_INSTALL_ROOT=%CMDER_ROOT%\vendor\git-for-windows"
  76. call :verbose-output Add the minimal git commands to the front of the path
  77. set "PATH=!GIT_INSTALL_ROOT!\cmd;%PATH%"
  78. ) else (
  79. goto :NO_GIT
  80. )
  81.  
  82. :FOUND_GIT
  83. :: Add git to the path
  84. if defined GIT_INSTALL_ROOT (
  85. rem add the unix commands at the end to not shadow windows commands like more
  86. call :verbose-output Enhancing PATH with unix commands from git in "%GIT_INSTALL_ROOT%\usr\bin"
  87. set "PATH=%PATH%;%GIT_INSTALL_ROOT%\usr\bin;%GIT_INSTALL_ROOT%\usr\share\vim\vim74"
  88. :: define SVN_SSH so we can use git svn with ssh svn repositories
  89. if not defined SVN_SSH set "SVN_SSH=%GIT_INSTALL_ROOT:\=\\%\\bin\\ssh.exe"
  90. )
  91.  
  92. :NO_GIT
  93. endlocal & set "PATH=%PATH%" & set "SVN_SSH=%SVN_SSH%" & set "GIT_INSTALL_ROOT=%GIT_INSTALL_ROOT%"
  94.  
  95. :: Enhance Path
  96. set "PATH=%CMDER_ROOT%\bin;%PATH%;%CMDER_ROOT%\"
  97.  
  98. :: Drop *.bat and *.cmd files into "%CMDER_ROOT%\config\profile.d"
  99. :: to run them at startup.
  100. if not exist "%CMDER_ROOT%\config\profile.d" (
  101. mkdir "%CMDER_ROOT%\config\profile.d"
  102. )
  103.  
  104. pushd "%CMDER_ROOT%\config\profile.d"
  105. for /f "usebackq" %%x in ( `dir /b *.bat *.cmd 2^>nul` ) do (
  106. call :verbose-output Calling "%CMDER_ROOT%\config\profile.d\%%x"...
  107. call "%CMDER_ROOT%\config\profile.d\%%x"
  108. )
  109. popd
  110.  
  111. :: Allows user to override default aliases store using profile.d
  112. :: scripts run above by setting the 'aliases' env variable.
  113. ::
  114. :: Note: If overriding default aliases store file the aliases
  115. :: must also be self executing, see '.\user-aliases.cmd.example',
  116. :: and be in profile.d folder.
  117. set "user-aliases=%CMDER_ROOT%\config\user-aliases.cmd"
  118.  
  119. :: The aliases environment variable is used by alias.bat to id
  120. :: the default file to store new aliases in.
  121. if not defined aliases (
  122. set "aliases=%user-aliases%"
  123. )
  124.  
  125. :: Make sure we have a self-extracting user-aliases.cmd file
  126. setlocal enabledelayedexpansion
  127. if not exist "%user-aliases%" (
  128. echo Creating initial user-aliases store in "%user-aliases%"...
  129. copy "%CMDER_ROOT%\vendor\user-aliases.cmd.example" "%user-aliases%"
  130. ) else (
  131. type "%user-aliases%" | findstr /i ";= Add aliases below here" >nul
  132. if "!errorlevel!" == "1" (
  133. echo Creating initial user-aliases store in "%user-aliases%"...
  134. copy "%CMDER_ROOT%\%user-aliases%" "%user-aliases%.old_format"
  135. copy "%CMDER_ROOT%\vendor\user-aliases.cmd.example" "%user-aliases%"
  136. )
  137. )
  138.  
  139. :: Update old 'user-aliases' to new self executing 'user-aliases.cmd'
  140. if exist "%CMDER_ROOT%\config\aliases" (
  141. echo Updating old "%CMDER_ROOT%\config\aliases" to new format...
  142. type "%CMDER_ROOT%\config\aliases" >> "%user-aliases%" && del "%CMDER_ROOT%\config\aliases"
  143. ) else if exist "%user-aliases%.old_format" (
  144. echo Updating old "%user-aliases%" to new format...
  145. type "%user-aliases%.old_format" >> "%user-aliases%" && del "%user-aliases%.old_format"
  146. )
  147. endlocal
  148. :: Add aliases to the environment
  149. call "%user-aliases%"
  150.  
  151. :: See vendor\git-for-windows\README.portable for why we do this
  152. :: Basically we need to execute this post-install.bat because we are
  153. :: manually extracting the archive rather than executing the 7z sfx
  154. if exist "%CMDER_ROOT%\vendor\git-for-windows\post-install.bat" (
  155. call :verbose-output Running Git for Windows one time Post Install....
  156. pushd "%CMDER_ROOT%\vendor\git-for-windows\"
  157. "%CMDER_ROOT%\vendor\git-for-windows\git-bash.exe" --no-needs-console --hide --no-cd --command=post-install.bat
  158. popd
  159. )
  160.  
  161. :: Set home path
  162. if not defined HOME set "HOME=%USERPROFILE%"
  163.  
  164. if exist "%CMDER_ROOT%\config\user-profile.cmd" (
  165. REM Create this file and place your own command in there
  166. call "%CMDER_ROOT%\config\user-profile.cmd"
  167. ) else (
  168. echo Creating user startup file: "%CMDER_ROOT%\config\user-profile.cmd"
  169. (
  170. echo :: use this file to run your own startup commands
  171. echo :: use in front of the command to prevent printing the command
  172. echo.
  173. echo :: uncomment this to have the ssh agent load when cmder starts
  174. echo :: call "%%GIT_INSTALL_ROOT%%/cmd/start-ssh-agent.cmd"
  175. echo.
  176. echo :: uncomment this next two lines to use pageant as the ssh authentication agent
  177. echo :: SET SSH_AUTH_SOCK=/tmp/.ssh-pageant-auth-sock
  178. echo :: call "%%GIT_INSTALL_ROOT%%/cmd/start-ssh-pageant.cmd"
  179. echo.
  180. echo :: you can add your plugins to the cmder path like so
  181. echo :: set "PATH=%%CMDER_ROOT%%\vendor\whatever;%%PATH%%"
  182. echo.
  183. ) > "%CMDER_ROOT%\config\user-profile.cmd"
  184. )
  185.  
  186. exit /b
  187.  
  188. ::
  189. :: sub-routines below here
  190. ::
  191. :verbose-output
  192. if %verbose-output% gtr 0 echo %*
  193. exit /b
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement