Skip to content

Commit

Permalink
Merge pull request #2779 from cmderdev/development
Browse files Browse the repository at this point in the history
Improvements to shells and general fixes
  • Loading branch information
DRSDavidSoft authored Nov 6, 2022
2 parents 47caafb + ba97011 commit e0ade8f
Show file tree
Hide file tree
Showing 15 changed files with 238 additions and 180 deletions.
7 changes: 6 additions & 1 deletion Cmder.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ SET CMDER_ROOT=%~dp0
@if "%CMDER_ROOT:~-1%" == "\" SET CMDER_ROOT=%CMDER_ROOT:~0,-1%

if not exist "%CMDER_ROOT%\config\user_ConEmu.xml" (
copy "%CMDER_ROOT%\vendor\ConEmu.xml.default" "%CMDER_ROOT%\config\user_ConEmu.xml"
if not exist "%CMDER_ROOT%\config" mkdir "%CMDER_ROOT%\config" 2>nul
copy "%CMDER_ROOT%\vendor\ConEmu.xml.default" "%CMDER_ROOT%\config\user_ConEmu.xml" 1>nul
if %errorlevel% neq 0 (
echo ERROR: CMDER Initialization has Failed
exit /b 1
)
)

if exist "%~1" (
Expand Down
4 changes: 2 additions & 2 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ if ($Compile) {
Pop-Location
}

if (-Not $noVendor) {
if (-not $noVendor) {
# Check for requirements
Ensure-Exists $sourcesPath
Ensure-Executable "7z"
Expand Down Expand Up @@ -162,7 +162,7 @@ if (-Not $noVendor) {
Pop-Location
}

if (-Not $Compile -Or $noVendor) {
if (-not $Compile -or $noVendor) {
Write-Warning "You are not building the full project, Use -Compile without -noVendor"
Write-Warning "This cannot be a release. Test build only!"
return
Expand Down
34 changes: 17 additions & 17 deletions scripts/update.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function Match-Filenames {

$position = 0

if ([String]::IsNullOrEmpty($filename) -Or [String]::IsNullOrEmpty($filenameDownload)) {
if ([String]::IsNullOrEmpty($filename) -or [String]::IsNullOrEmpty($filenameDownload)) {
throw "Either one or both filenames are empty!"
}

Expand Down Expand Up @@ -88,15 +88,15 @@ function Fetch-DownloadUrl {

$url = [uri] $urlStr

if ((-Not $url) -Or ($null -eq $url) -Or ($url -eq '')) {
if ((-not $url) -or ($null -eq $url) -or ($url -eq '')) {
throw "Failed to parse url: $urlStr"
}

if (-Not ("http", "https" -Contains $url.Scheme)) {
if (-not ("http", "https" -contains $url.Scheme)) {
throw "unknown source scheme: $($url.Scheme)"
}

if (-Not ($url.Host -ilike "*github.com")) {
if (-not ($url.Host -ilike "*github.com")) {
throw "unknown source domain: $($url.Host)"
}

Expand All @@ -116,12 +116,12 @@ function Fetch-DownloadUrl {

$charCount = 0

if (-Not ($info -Is [array])) {
if (-not ($info -is [array])) {
throw "The response received from API server is invalid"
}

:loop foreach ($i in $info) {
if (-Not ($i.assets -Is [array])) {
if (-not ($i.assets -is [array])) {
continue
}

Expand Down Expand Up @@ -157,12 +157,12 @@ function Fetch-DownloadUrl {
}

# Special case for archive downloads of repository
if (($null -eq $downloadLinks) -Or (-Not $downloadLinks)) {
if ((($p | % { $_.Trim('/') }) -Contains "archive") -And $info[0].tag_name) {
if (($null -eq $downloadLinks) -or (-not $downloadLinks)) {
if ((($p | ForEach-Object { $_.Trim('/') }) -contains "archive") -and $info[0].tag_name) {
for ($i = 0; $i -lt $p.Length; $i++) {
if ($p[$i].Trim('/') -eq "archive") {
$p[$i + 1] = $info[0].tag_name + ".zip"
$downloadLinks = $url.Scheme + "://" + $url.Host + ($p -Join '')
$downloadLinks = $url.Scheme + "://" + $url.Host + ($p -join '')
return $downloadLinks
}
}
Expand All @@ -188,11 +188,11 @@ function Fetch-DownloadUrl {

$downloadLinks = $temp | Where-Object { (Match-Filenames $url $_ true) -eq $charCount }

if (($null -eq $downloadLinks) -Or (-Not $downloadLinks)) {
if (($null -eq $downloadLinks) -or (-not $downloadLinks)) {
throw "No suitable download links matched for the url!"
}

if (-Not($downloadLinks -is [String])) {
if (-not($downloadLinks -is [String])) {
throw "Found multiple matches for the same url:`n" + $downloadLinks
}

Expand All @@ -211,7 +211,7 @@ foreach ($s in $sources) {

$downloadUrl = Fetch-DownloadUrl $s.url

if (($null -eq $downloadUrl) -Or ($downloadUrl -eq '')) {
if (($null -eq $downloadUrl) -or ($downloadUrl -eq '')) {
Write-Verbose "No new links were found"
continue
}
Expand All @@ -222,15 +222,15 @@ foreach ($s in $sources) {

$version = ''

if ( ($url.Segments[-3] -eq "download/") -And ($url.Segments[-2].StartsWith("v")) ) {
if (($url.Segments[-3] -eq "download/") -and ($url.Segments[-2].StartsWith("v"))) {
$version = $url.Segments[-2].TrimStart('v').TrimEnd('/')
}

if ( ($url.Segments[-2] -eq "archive/") ) {
if (($url.Segments[-2] -eq "archive/")) {
$version = [System.IO.Path]::GetFileNameWithoutExtension($url.Segments[-1].TrimStart('v').TrimEnd('/'))
}

if ( $version -eq '' ) {
if ($version -eq '') {
throw "Unable to extract version from url string"
}

Expand All @@ -255,11 +255,11 @@ if ($count -eq 0) {
return
}

if ( $Env:APPVEYOR -eq 'True' ) {
if ($Env:APPVEYOR -eq 'True') {
Add-AppveyorMessage -Message "Successfully updated $count dependencies." -Category Information
}

if ( $Env:GITHUB_ACTIONS -eq 'true' ) {
if ($Env:GITHUB_ACTIONS -eq 'true') {
Write-Output "::notice title=Task Complete::Successfully updated $count dependencies."
}

Expand Down
20 changes: 11 additions & 9 deletions scripts/utils.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ function Delete-Existing($path) {
function Extract-Archive($source, $target) {
Write-Verbose $("Extracting Archive '$cmder_root\vendor\" + $source.replace('/','\') + " to '$cmder_root\vendor\$target'")
Invoke-Expression "7z x -y -o`"$($target)`" `"$source`" > `$null"
if ($lastexitcode -ne 0) {
if ($LastExitCode -ne 0) {
Write-Error "Extracting of $source failed"
}
Remove-Item $source
}

function Create-Archive($source, $target, $params) {
$command = "7z a -xr@`"$source\packignore`" $params `"$target`" `"$source\*`" > `$null"
$command = "7z a -x@`"$source\packignore`" $params `"$target`" `"*`" > `$null"
Write-Verbose "Creating Archive from '$source' in '$target' with parameters '$params'"
Push-Location $source
Invoke-Expression $command
if ($lastexitcode -ne 0) {
Pop-Location
if ($LastExitCode -ne 0) {
Write-Error "Compressing $source failed"
}
}
Expand All @@ -54,7 +56,7 @@ function Flatten-Directory($name) {
$moving = "$($name)_moving"
Rename-Item $name -NewName $moving
Write-Verbose "Flattening the '$name' directory..."
$child = (Get-Childitem $moving)[0] | Resolve-Path
$child = (Get-ChildItem $moving)[0] | Resolve-Path
Move-Item -Path $child -Destination $name
Remove-Item -Recurse $moving
}
Expand All @@ -78,7 +80,7 @@ function Set-GHVariable {
Write-Verbose "Setting CI variable $Name to $Value" -Verbose

if ($env:GITHUB_ENV) {
echo "$Name=$Value" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
Write-Output "$Name=$Value" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding utf8
}
}

Expand Down Expand Up @@ -130,7 +132,7 @@ function Parse-Changelog($file) {
[regex]$regex = '^## \[(?<version>[\w\-\.]+)\]\([^\n()]+\)\s+\([^\n()]+\)$';

# Find the first match of the version string which means the latest version
$version = Select-String -Path $file -Pattern $regex | Select-Object -First 1 | % { $_.Matches.Groups[1].Value }
$version = Select-String -Path $file -Pattern $regex | Select-Object -First 1 | ForEach-Object { $_.Matches.Groups[1].Value }

return $version
}
Expand Down Expand Up @@ -226,12 +228,12 @@ function Download-File {

$useBitTransfer = $null -ne (Get-Module -Name BitsTransfer -ListAvailable) -and ($PSVersionTable.PSVersion.Major -le 5)

$File = $File -Replace "/", "\"
$File = $File -replace "/", "\"

try {
if ($useBitTransfer) {
Start-BitsTransfer -Source $Url -Destination $File -DisplayName "Downloading $Url to $File"
Return
Start-BitsTransfer -Source $Url -Destination $File -DisplayName "Downloading '$Url' to $File"
return
}
}
catch {
Expand Down
8 changes: 4 additions & 4 deletions vendor/clink.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@ end


local function get_clean_color()
return clean_color or "\x1b[1;37;49m"
return clean_color or "\x1b[37;1m" -- White, Bold
end


local function get_dirty_color()
return dirty_color or "\x1b[33;3m"
return dirty_color or "\x1b[33;3m" -- Yellow, Italic
end


local function get_conflict_color()
return conflict_color or "\x1b[31;1m"
return conflict_color or "\x1b[31;1m" -- Red, Bold
end

local function get_unknown_color()
return unknown_color or "\x1b[37;1m"
return unknown_color or "\x1b[37;1m" -- White, Bold
end

---
Expand Down
10 changes: 6 additions & 4 deletions vendor/cmder_prompt_config.lua.default
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ prompt_overrideSvnStatusOptIn = false

-- Prompt Attributes
--
-- Colors
-- Colors: https://github.com/cmderdev/cmder/wiki/Customization#list-of-colors
-- Effects: https://github.com/cmderdev/cmder/wiki/Customization#list-of-effects
--
-- Green: "\x1b[1;33;49m"
-- Yellow: "\x1b[1;32;49m"
-- Light Grey: "\x1b[1;30;49m"
Expand All @@ -54,7 +56,7 @@ prompt_overrideSvnStatusOptIn = false
uah_color = "\x1b[1;33;49m" -- Green = uah = [user]@[hostname]
cwd_color = "\x1b[1;32;49m" -- Yellow cwd = Current Working Directory
lamb_color = "\x1b[1;30;49m" -- Light Grey = Lambda Color
clean_color = "\x1b[1;37;49m"
dirty_color = "\x1b[33;3m"
conflict_color = "\x1b[31;1m"
clean_color = "\x1b[37;1m"
dirty_color = "\x1b[33;3m" -- Yellow, Italic
conflict_color = "\x1b[31;1m" -- Red, Bold
unknown_color = "\x1b[37;1m" -- White = No VCS Status Branch Color
38 changes: 31 additions & 7 deletions vendor/init.bat
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ if "%CMDER_ROOT:~-1%" == "\" SET "CMDER_ROOT=%CMDER_ROOT:~0,-1%"

:: Include Cmder libraries
call "%cmder_root%\vendor\bin\cexec.cmd" /setpath
call "%cmder_root%\vendor\lib\lib_console"
call "%cmder_root%\vendor\lib\lib_base"
call "%cmder_root%\vendor\lib\lib_path"
call "%cmder_root%\vendor\lib\lib_console"
call "%cmder_root%\vendor\lib\lib_git"
call "%cmder_root%\vendor\lib\lib_profile"

Expand Down Expand Up @@ -89,7 +89,7 @@ call "%cmder_root%\vendor\lib\lib_profile"
set "GIT_INSTALL_ROOT=%~2"
shift
) else (
%print_error% "The Git install root folder "%~2", you specified does not exist!"
%print_error% "The Git install root folder "%~2" that you specified does not exist!"
exit /b
)
) else if /i "%1" == "/nix_tools" (
Expand All @@ -111,7 +111,7 @@ call "%cmder_root%\vendor\lib\lib_profile"
set "HOME=%~2"
shift
) else (
%print_error% The home folder "%2", you specified does not exist!
%print_error% The home folder "%2" that you specified does not exist!
exit /b
)
) else if /i "%1" == "/svn_ssh" (
Expand All @@ -124,6 +124,13 @@ call "%cmder_root%\vendor\lib\lib_profile"
goto :var_loop

:start
:: Enable console related methods if verbose/debug is turned on
if %debug_output% gtr 0 (set print_debug=%lib_console% debug_output)
if %verbose_output% gtr 0 (
set print_verbose=%lib_console% verbose_output
set print_warning=%lib_console% show_warning
)

:: Sets CMDER_SHELL, CMDER_CLINK, CMDER_ALIASES variables
%lib_base% cmder_shell
%print_debug% init.bat "Env Var - CMDER_ROOT=%CMDER_ROOT%"
Expand All @@ -140,13 +147,22 @@ if defined CMDER_USER_CONFIG (
set CMDER_CONFIG_DIR=%CMDER_USER_CONFIG%
)

if not "%CMDER_SHELL%" == "cmd" (
%print_warning% "Incompatible 'ComSpec/Shell' Detetected: %CMDER_SHELL%"
set CMDER_CLINK=0
set CMDER_ALIASES=0
)

:: Pick right version of Clink
if "%PROCESSOR_ARCHITECTURE%"=="x86" (
set clink_architecture=x86
set architecture_bits=32
) else (
) else if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
set clink_architecture=x64
set architecture_bits=64
) else (
%print_warning% "Incompatible Processor Detetected: %PROCESSOR_ARCHITECTURE%"
set CMDER_CLINK=0
)

if "%CMDER_CLINK%" == "1" (
Expand Down Expand Up @@ -182,10 +198,18 @@ if "%CMDER_CLINK%" == "1" (
"%CMDER_ROOT%\vendor\clink\clink_%clink_architecture%.exe" inject --quiet --profile "%CMDER_CONFIG_DIR%" --scripts "%CMDER_ROOT%\vendor"

if errorlevel 1 (
%print_error% "Failed to initialize Clink with error code: %errorlevel%"
%print_error% "Clink initilization has failed with error code: %errorlevel%"
)
) else (
%print_verbose% "WARNING: Incompatible 'ComSpec/Shell' Detetected, Skipping Clink Injection!"
%print_warning% "Skipping Clink Injection!"

for /f "tokens=2 delims=:." %%x in ('chcp') do set cp=%%x
chcp 65001>nul

:: Revert back to plain cmd.exe prompt without clink
prompt $E[1;32;49m$P$S$_$E[1;30;49mλ$S$E[0m

chcp %cp%>nul
)

if "%CMDER_CONFIGURED%" GTR "1" (
Expand Down Expand Up @@ -265,7 +289,7 @@ goto :CONFIGURE_GIT
:: Add git to the path
if exist "%GIT_INSTALL_ROOT%\cmd\git.exe" %lib_path% enhance_path "%GIT_INSTALL_ROOT%\cmd" ""

:: Add the unix commands at the end to not shadow windows commands like more and find
:: 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"
Expand Down
4 changes: 0 additions & 4 deletions vendor/lib/lib_base.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,9 @@ exit /b
set CMDER_SHELL=%~n1
if not defined CMDER_CLINK (
set CMDER_CLINK=1
if "%CMDER_SHELL%" equ "tcc" set CMDER_CLINK=0
if "%CMDER_SHELL%" equ "tccle" set CMDER_CLINK=0
)
if not defined CMDER_ALIASES (
set CMDER_ALIASES=1
if "%CMDER_SHELL%" equ "tcc" set CMDER_ALIASES=0
if "%CMDER_SHELL%" equ "tccle" set CMDER_ALIASES=0
)
exit /b

Expand Down
Loading

0 comments on commit e0ade8f

Please sign in to comment.