Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion vendor/init.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -222,13 +222,13 @@ goto :SKIP_CLINK
)

"%CMDER_ROOT%\vendor\clink\clink_%clink_architecture%.exe" inject --quiet --profile "%CMDER_CONFIG_DIR%" --scripts "%CMDER_ROOT%\vendor"
set CMDER_CLINK=2

:: Check if a fatal error occurred when trying to inject Clink
if errorlevel 2 (
REM %print_error% "Clink injection has failed with error code: %errorlevel%"
goto :SKIP_CLINK
)
set CMDER_CLINK=2

goto :CLINK_FINISH

Expand Down
193 changes: 38 additions & 155 deletions vendor/user_init.cmd.template
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
:: powershell -f %cmder_root%\vendor\bin\create-cmdercfg.ps1 -shell cmd [-outfile "[filename]"]
::

if "%CMDER_CONFIGURED%" == "1" (
goto CMDER_CONFIGURED
)

if "%CMDER_CLINK%" == "1" (
goto :INJECT_CLINK
) else if "%CMDER_CLINK%" == "2" if defined WT_PROFILE_ID (
Expand All @@ -25,40 +29,20 @@ goto :SKIP_CLINK

:: Check if Clink is not present
if not exist "%CMDER_ROOT%\vendor\clink\clink_%clink_architecture%.exe" (
%print_error% "Clink executable is not present in 'vendor\clink\clink_%clink_architecture%.exe'"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daxgames Assuming the Cmder directory content hasn't changed, correct?

Also, I'm considering whether the if branch in batch causes slow downs, if it does, I need to pay more attention to usages like this in other places as well

:: This allows the user to install Clink globally and remove it from Cmder if they wish.
:: The user may also want to remove parts of the SKIP_CLINK section.
goto :SKIP_CLINK
)

:: Run Clink
if not exist "%CMDER_CONFIG_DIR%\settings" if not exist "%CMDER_CONFIG_DIR%\clink_settings" (
echo Generating Clink initial settings in "%CMDER_CONFIG_DIR%\clink_settings"
copy "%CMDER_ROOT%\vendor\clink_settings.default" "%CMDER_CONFIG_DIR%\clink_settings"
echo Additional *.lua files in "%CMDER_CONFIG_DIR%" are loaded on startup.
)

if not exist "%CMDER_CONFIG_DIR%\cmder_prompt_config.lua" (
echo Creating Cmder prompt config file: "%CMDER_CONFIG_DIR%\cmder_prompt_config.lua"
copy "%CMDER_ROOT%\vendor\cmder_prompt_config.lua.default" "%CMDER_CONFIG_DIR%\cmder_prompt_config.lua"
)

:: Cleanup legacy Clink Settings file
if exist "%CMDER_CONFIG_DIR%\settings" if exist "%CMDER_CONFIG_DIR%\clink_settings" (
del "%CMDER_CONFIG_DIR%\settings"
)

:: Cleanup legacy Clink history file
if exist "%CMDER_CONFIG_DIR%\.history" if exist "%CMDER_CONFIG_DIR%\clink_history" (
del "%CMDER_CONFIG_DIR%\.history"
)

Comment on lines -44 to -53

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@daxgames These legacy clean ups are one time jobs that meant to be executed from init.bat once instead of every time by init_user.cmd, correct?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

"%CMDER_ROOT%\vendor\clink\clink_%clink_architecture%.exe" inject --quiet --profile "%CMDER_CONFIG_DIR%" --scripts "%CMDER_ROOT%\vendor"
set CMDER_CLINK=2

:: Check if a fatal error occurred when trying to inject Clink
if errorlevel 2 (
goto :SKIP_CLINK
%print_error% "Clink initialization has failed with error code: %errorlevel%"
goto :SKIP_CLINK
)

set CMDER_CLINK=2
goto :CLINK_FINISH

:SKIP_CLINK
Expand All @@ -76,79 +60,58 @@ goto :SKIP_CLINK
chcp %cp%>nul

:CLINK_FINISH
if not defined GIT_INSTALL_ROOT set "GIT_INSTALL_ROOT=$env:GIT_INSTALL_ROOT"
if not defined SVN_SSH set "SVN_SSH=$env:SVN_SSH"
if not defined git_locale set "git_locale=$env:git_locale"
if not defined LANG set "LANG=$env:LANG"
if not defined user_aliases set "user_aliases=$env:user_aliases"
if not defined aliases set "aliases=%user_aliases%"
if not defined HOME set "HOME=%USERPROFILE%"

if "%CMDER_CONFIGURED%" GTR "1" (
%print_verbose% "Cmder is already configured, skipping Cmder Init!"

goto :USER_ALIASES
) else if "%CMDER_CONFIGURED%" == "1" (
%print_verbose% "Cmder is already configured, skipping to Cmder User Init!"

goto :USER_CONFIG_START
)

if not defined GIT_INSTALL_ROOT set "GIT_INSTALL_ROOT=$env:GIT_INSTALL_ROOT"
if not defined SVN_SSH set "SVN_SSH=$env:SVN_SSH"
if not defined git_locale set "git_locale=$env:git_locale"
if not defined LANG set "LANG=$env:LANG"
if not defined HOME set "HOME=%USERPROFILE%"
set "PLINK_PROTOCOL=$env:PLINK_PROTOCOL"

set "PLINK_PROTOCOL=$env:PLINK_PROTOCOL"
if exist "%GIT_INSTALL_ROOT%\cmd\git.exe" (
set "path=%GIT_INSTALL_ROOT%\cmd;%path%"
)

%print_debug% init.cmd "START - git.exe(prepend): Env Var - PATH=%path%"
if exist "%GIT_INSTALL_ROOT%\cmd\git.exe" (
set "path=%GIT_INSTALL_ROOT%\cmd;%path%"
)
%print_debug% init.cmd "END - git.exe(prepend): Env Var - PATH=%path%"

:: Add the unix commands at the end to not shadow windows commands like `more` and `find`
if %nix_tools% equ 1 (
%print_verbose% "Preferring Windows commands"
set "path_position=append"
) else (
%print_verbose% "Preferring *nix commands"
set "path_position="
)
:: Add the unix commands at the end to not shadow windows commands like `more` and `find`
set path_position_nix_tools=append
if %nix_tools% equ 2 (
set "path_position_nix_tools=prepend"
)

%print_debug% init.cmd "START - nix_tools(%path_position%): Env Var - PATH=%path%"
set "git_mingw_bin="
if exist "%GIT_INSTALL_ROOT%\mingw32" (
set "git_mingw_bin=%GIT_INSTALL_ROOT%\mingw32\bin"
) else if exist "%GIT_INSTALL_ROOT%\mingw64" (
set "git_mingw_bin=%GIT_INSTALL_ROOT%\mingw64\bin"
)
:: TODO: Support for ARM

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Related ARM for Clink are in #3018, I'm looking forward to getting that merged into development as well, especially with the relevance of more and more ARM machines, like Microsoft's own Surface line

Keeping these here for my own reference

set "git_mingw_bin="
if "%PROCESSOR_ARCHITECTURE%" == "x86" if exist "%GIT_INSTALL_ROOT%\mingw32" (
set "git_mingw_bin=%GIT_INSTALL_ROOT%\mingw32\bin"
) else if "%PROCESSOR_ARCHITECTURE%" == "AMD64" if exist "%GIT_INSTALL_ROOT%\mingw64" (
set "git_mingw_bin=%GIT_INSTALL_ROOT%\mingw64\bin"
)

%lib_path% add_path_with_position "%git_mingw_bin%" "%path_position%"
%lib_path% add_path_with_position "%GIT_INSTALL_ROOT%\usr\bin" "%path_position%"
%print_debug% init.cmd "END - nix_tools(%path_position%): Env Var - PATH=%path%"
%lib_path% add_path_with_position "%git_mingw_bin%" "%path_position_nix_tools%"
%lib_path% add_path_with_position "%GIT_INSTALL_ROOT%\usr\bin" "%path_position_nix_tools%"

%print_debug% init.cmd "START - vendor/bin(prepend): Env Var - PATH=%path%"
set "path=%CMDER_ROOT%\vendor\bin;%path%"
%print_debug% init.cmd "END - vendor/bin(prepend): Env Var - PATH=%path%"
set "path=%CMDER_ROOT%\vendor\bin;%path%"

:USER_CONFIG_START
%print_debug% init.cmd "START - bin(prepend): Env Var - PATH=%path%"
if %max_depth% gtr 1 (
%lib_path% enhance_path_recursive "%CMDER_ROOT%\bin" 0 %max_depth%
) else (
set "path=%CMDER_ROOT%\bin;%path%"
)
%print_debug% init.cmd "END - bin(prepend): Env Var - PATH=%path%"

:: The CMDER_USER_BIN variable is set in the launcher.
if defined CMDER_USER_BIN (
%print_debug% init.cmd "START - user_bin(prepend): Env Var - PATH=%path%"
if %max_depth% gtr 1 (
%lib_path% enhance_path_recursive "%CMDER_USER_BIN%" 0 %max_depth%
) else (
set "path=%CMDER_USER_BIN%;%path%"
)
%print_debug% init.cmd "END - user_bin(prepend): Env Var - PATH=!path!"
)

%print_debug% init.cmd "START - cmder_root(append): Env Var - PATH=%path%"
set "path=%path%;%CMDER_ROOT%"
%print_debug% init.cmd "END - cmder_root(append): Env Var - PATH=%path%"

call "%user_aliases%"

:: Drop *.bat and *.cmd files into "%CMDER_ROOT%\config\profile.d"
:: to run them at startup.
Expand All @@ -157,91 +120,13 @@ set "path=%CMDER_ROOT%\vendor\bin;%path%"
%lib_profile% run_profile_d "%CMDER_USER_CONFIG%\profile.d"
)

:USER_ALIASES
:: Allows user to override default aliases store using profile.d
:: scripts run above by setting the 'aliases' env variable.
::
:: Note: If overriding default aliases store file the aliases
:: must also be self executing, see '.\user_aliases.cmd.default',
:: and be in profile.d folder.
if not defined user_aliases (
set "user_aliases=%CMDER_CONFIG_DIR%\user_aliases.cmd"
)

if "%CMDER_ALIASES%" == "1" (
REM The aliases environment variable is used by alias.cmd to id
REM the default file to store new aliases in.
if not defined aliases (
set "aliases=%user_aliases%"
)

REM Make sure we have a self-extracting user_aliases.cmd file
if not exist "%user_aliases%" (
echo Creating initial user_aliases store in "%user_aliases%"...
copy "%CMDER_ROOT%\vendor\user_aliases.cmd.default" "%user_aliases%"
) else (
%lib_base% update_legacy_aliases
)

:: Update old 'user_aliases' to new self executing 'user_aliases.cmd'
if exist "%CMDER_ROOT%\config\aliases" (
echo Updating old "%CMDER_ROOT%\config\aliases" to new format...
type "%CMDER_ROOT%\config\aliases" >> "%user_aliases%"
del "%CMDER_ROOT%\config\aliases"
) else if exist "%user_aliases%.old_format" (
echo Updating old "%user_aliases%" to new format...
type "%user_aliases%.old_format" >> "%user_aliases%"
del "%user_aliases%.old_format"
)
)

:: Add aliases to the environment
type "%user_aliases%" | %WINDIR%\System32\findstr /b /l /i "history=cat " >nul
if "%ERRORLEVEL%" == "0" (
echo Migrating alias 'history' to new Clink 1.x.x...
call "%CMDER_ROOT%\vendor\bin\alias.cmd" /d history
echo Restart the session to activate changes!
)

call "%user_aliases%"

if "%CMDER_CONFIGURED%" gtr "1" goto :CMDER_CONFIGURED

set "initialConfig=%CMDER_ROOT%\config\user_profile.cmd"
if exist "%CMDER_ROOT%\config\user_profile.cmd" (
REM Create this file and place your own command in there
%print_debug% init.cmd "Calling - %CMDER_ROOT%\config\user_profile.cmd"
call "%CMDER_ROOT%\config\user_profile.cmd"
)

call "%CMDER_ROOT%\config\user_profile.cmd"
if defined CMDER_USER_CONFIG (
set "initialConfig=%CMDER_USER_CONFIG%\user_profile.cmd"
if exist "%CMDER_USER_CONFIG%\user_profile.cmd" (
REM Create this file and place your own command in there
%print_debug% init.cmd "Calling - %CMDER_USER_CONFIG%\user_profile.cmd"
call "%CMDER_USER_CONFIG%\user_profile.cmd"
)
)

if not exist "%initialConfig%" (
echo Creating user startup file: "%initialConfig%"
copy "%CMDER_ROOT%\vendor\user_profile.cmd.default" "%initialConfig%"
)

if "%CMDER_ALIASES%" == "1" if exist "%CMDER_ROOT%\bin\alias.bat" if exist "%CMDER_ROOT%\vendor\bin\alias.cmd" (
echo Cmder's 'alias' command has been moved into "%CMDER_ROOT%\vendor\bin\alias.cmd"
echo to get rid of this message either:
echo.
echo Delete the file "%CMDER_ROOT%\bin\alias.bat"
echo.
echo or
echo.
echo If you have customized it and want to continue using it instead of the included version
echo * Rename "%CMDER_ROOT%\bin\alias.bat" to "%CMDER_ROOT%\bin\alias.cmd".
echo * Search for 'user-aliases' and replace it with 'user_aliases'.
)

set initialConfig=
set "path=%path:;;=;%"

:CMDER_CONFIGURED
Expand All @@ -256,14 +141,12 @@ set "path=%CMDER_ROOT%\vendor\bin;%path%"
:CLEANUP
set architecture_bits=
set CMDER_ALIASES=
set CMDER_CLINK=
set CMDER_INIT_END=
set CMDER_INIT_START=
set CMDER_USER_FLAGS=
set debug_output=
set fast_init=
set git_mingw_bin=
set initialConfig=
set max_depth=
set nix_tools=
set path_position=
Expand Down
Loading