Make PowerShell profile.ps1's debug and verbose working correctly

This commit is contained in:
David Refoua
2025-11-09 04:29:32 +03:30
parent 9c3bbe9b24
commit dc3b142b32
2 changed files with 30 additions and 23 deletions

View File

@@ -49,6 +49,7 @@ jobs:
- name: Testing PowerShell
run: |
PowerShell.exe -ExecutionPolicy Bypass -NoLogo -NoProfile -Command "$CMDER_DEBUG = 1; 'vendor\profile.ps1' 4>&1 5>&1"
PowerShell.exe -ExecutionPolicy Bypass -NoLogo -NoProfile -Command "$env:CMDER_DEBUG='1'; . 'vendor\profile.ps1'" 4>&1 5>&1
- name: Testing Bash
run: |
bash vendor/cmder.sh

34
vendor/profile.ps1 vendored
View File

@@ -5,22 +5,13 @@
# !!! THIS FILE IS OVERWRITTEN WHEN CMDER IS UPDATED
# !!! Use "%CMDER_ROOT%\config\user_profile.ps1" to add your own startup commands
if ($env:CMDER_DEBUG -and ($env:CMDER_DEBUG -match '^(1|true)$')) {
$DebugPreference = 'Continue'
$VerbosePreference = 'Continue'
}
$CMDER_INIT_START = Get-Date
# Compatibility with PS major versions <= 2
# Determine the script root if not already set
if (!$PSScriptRoot) {
$PSScriptRoot = Split-Path $Script:MyInvocation.MyCommand.Path
}
if ($ENV:CMDER_USER_CONFIG) {
Write-Verbose "CMDER IS ALSO USING INDIVIDUAL USER CONFIG FROM '$ENV:CMDER_USER_CONFIG'!"
}
# We do this for Powershell as Admin Sessions because CMDER_ROOT is not being set.
if (!$ENV:CMDER_ROOT) {
if ($ENV:ConEmuDir) {
@@ -36,6 +27,12 @@ $ENV:CMDER_ROOT = ($ENV:CMDER_ROOT).TrimEnd("\")
# Recent PowerShell versions include PowerShellGet out of the box
$moduleInstallerAvailable = [bool](Get-Command -Name 'Install-Module' -ErrorAction SilentlyContinue)
# Enable Debug and Verbose output if CMDER_DEBUG environment variable is set to '1' or 'true'
if ($env:CMDER_DEBUG -and ($env:CMDER_DEBUG -match '^(1|true)$')) {
$DebugPreference = 'Continue'
$VerbosePreference = 'Continue'
}
# Add Cmder modules directory to the autoload path.
$CmderModulePath = Join-path $PSScriptRoot "psmodules/"
@@ -48,17 +45,26 @@ if (-not $moduleInstallerAvailable -and -not $env:PSModulePath.Contains($CmderMo
$env:PSModulePath = $env:PSModulePath.Insert(0, "$CmderModulePath;")
}
if ($ENV:CMDER_USER_CONFIG) {
Write-Verbose "CMDER IS ALSO USING INDIVIDUAL USER CONFIG FROM '$ENV:CMDER_USER_CONFIG'!"
}
# Read vendored Git Version
$gitVersionVendor = Get-GitVersion -GitPath "$ENV:CMDER_ROOT\vendor\git-for-windows\cmd"
Write-Debug "GIT VENDOR: ${gitVersionVendor}"
$gitVendorPath = Join-Path $ENV:CMDER_ROOT 'vendor\git-for-windows\cmd'
$gitVersionVendor = Get-GitVersion -GitPath $gitVendorPath
if (-not [string]::IsNullOrEmpty($gitVersionVendor)) {
Write-Debug "GIT VENDOR: ${gitVersionVendor}"
} else {
Write-Debug "GIT VENDOR is not present at '$gitVendorPath'"
}
# Get user installed Git version(s) if found, and compare them with vendored version.
foreach ($git in (Get-Command -ErrorAction SilentlyContinue 'git')) {
Write-Debug "GIT PATH: {$git.Path}"
Write-Debug "GIT USER PATH: $($git.Path)"
$gitDir = Split-Path -Path $git.Path
$gitDir = Get-GitShimPath -GitPath $gitDir
$gitVersionUser = Get-GitVersion -GitPath $gitDir
Write-Debug "GIT USER: ${gitVersionUser}"
Write-Debug "GIT USER VERSION: ${gitVersionUser}"
$useGitVersion = Compare-GitVersion -UserVersion $gitVersionUser -VendorVersion $gitVersionVendor
Write-Debug "Using Git Version: ${useGitVersion}"