fix multiuser user_init.cmd creation

This commit is contained in:
Dax T. Games 2023-07-03 16:19:07 -04:00
parent 615ba5f816
commit 4bf659833c
3 changed files with 17 additions and 22 deletions

View File

@ -2,18 +2,23 @@
param(
[Parameter()]
[string]$shell = 'cmd',
[string]$outfile = "$env:cmder_root\config\user_init.cmd"
[string]$outfile = "$env:cmder_config_dir\user_init.cmd"
)
if ($shell -match 'powershell') {
write-host "'$shell' is not supported at this time!"
exit 0
} elseif ($shell -match 'bash') {
write-host "'$shell' is not supported at this time!"
exit 0
}
$CmderModulePath = Join-path $env:cmder_root "vendor/psmodules/"
$CmderFunctions = Join-Path $CmderModulePath "Cmder.ps1"
. $CmderFunctions
if ($shell -match 'cmd') {
write-host "Generating Cmder Config for '$shell' shell in '$outfile'..."
templateExpand "$env:cmder_root\vendor\user_init.cmd.template" "$outfile"
} elseif ($shell -match 'powershell') {
write-host "'$shell' is not supported at this time!"
} elseif ($shell -match 'bash') {
write-host "'$shell' is not supported at this time!"
}

19
vendor/init.bat vendored
View File

@ -168,10 +168,11 @@ if "%PROCESSOR_ARCHITECTURE%"=="x86" (
if defined CMDER_USER_CONFIG (
if exist "%CMDER_ROOT%\config\user_init.cmd" (
call "%CMDER_ROOT%\config\user_init.cmd"
exit /b
) else if exist "%CMDER_USER_CONFIG%\config\user_init.cmd" (
call "%CMDER_USER_CONFIG%\config\user_init.cmd"
exit /b
)
exit /b
) else if exist "%CMDER_ROOT%\config\user_init.cmd" (
call "%CMDER_ROOT%\config\user_init.cmd"
exit /b
@ -538,20 +539,8 @@ if "%CMDER_ALIASES%" == "1" if exist "%CMDER_ROOT%\bin\alias.bat" if exist "%CMD
set initialConfig=
if defined CMDER_USER_CONFIG (
if not exist "%CMDER_ROOT%\config\user_init.cmd" if not exist "%CMDER_USER_ROOT%\config\user_init.cmd" (
powershell -f %cmder_root%\vendor\bin\create-cmdercfg.ps1 -shell cmd -outfile "%CMDER_ROOT%\config\user_init.cmd"
)
if not exist "%CMDER_ROOT%\config\user_init.cmd" if not exist "%CMDER_USER_ROOT%\config\user_init.cmd" (
powershell -f %cmder_root%\vendor\bin\create-cmdercfg.ps1 -shell cmd -outfile "%CMDER_iUSER_ROOT%\config\user_init.cmd"
)
if not exist "%CMDER_ROOT%\config\user_init.cmd" if not exist "%CMDER_USER_ROOT%\config\user_init.cmd" (
%print_error% "Failed to generate Cmder config"
)
) else if not exist "%CMDER_ROOT%\config\user_init.cmd" (
powershell -f %cmder_root%\vendor\bin\create-cmdercfg.ps1 -shell cmd -outfile "%CMDER_ROOT%\config\user_init.cmd"
if not exist "%CMDER_CONFIG_DIR%\user_init.cmd" (
powershell -f "%cmder_root%\vendor\bin\create-cmdercfg.ps1" -shell cmd -outfile "%CMDER_CONFIG_DIR%\user_init.cmd"
if not exist "%CMDER_ROOT%\config\user_init.cmd" (
%print_error% "Failed to generate Cmder config"

View File

@ -186,8 +186,9 @@ function yOrn( $question ) {
return $Answer
}
function templateExpand($template, $outfile) {
$template = Get-Content $template -Raw
function templateExpand($template_filename, $outfile) {
$template = Get-Content "$template_filename" -Raw
$expanded = Invoke-Expression "@`"`r`n$template`r`n`"@"
$overwrite = 'y'