55# !!! THIS FILE IS OVERWRITTEN WHEN CMDER IS UPDATED
66# !!! Use "%CMDER_ROOT%\config\user_profile.ps1" to add your own startup commands
77
8- if ($env: CMDER_DEBUG -and ($env: CMDER_DEBUG -match ' ^(1|true)$' )) {
9- $DebugPreference = ' Continue'
10- $VerbosePreference = ' Continue'
11- }
12-
138$CMDER_INIT_START = Get-Date
149
15- # Compatibility with PS major versions <= 2
10+ # Determine the script root if not already set
1611if (! $PSScriptRoot ) {
1712 $PSScriptRoot = Split-Path $Script :MyInvocation.MyCommand.Path
1813}
1914
20- if ($ENV: CMDER_USER_CONFIG ) {
21- Write-Verbose " CMDER IS ALSO USING INDIVIDUAL USER CONFIG FROM '$ENV: CMDER_USER_CONFIG '!"
22- }
23-
2415# We do this for Powershell as Admin Sessions because CMDER_ROOT is not being set.
2516if (! $ENV: CMDER_ROOT ) {
2617 if ($ENV: ConEmuDir ) {
@@ -36,6 +27,12 @@ $ENV:CMDER_ROOT = ($ENV:CMDER_ROOT).TrimEnd("\")
3627# Recent PowerShell versions include PowerShellGet out of the box
3728$moduleInstallerAvailable = [bool ](Get-Command - Name ' Install-Module' - ErrorAction SilentlyContinue)
3829
30+ # Enable Debug and Verbose output if CMDER_DEBUG environment variable is set to '1' or 'true'
31+ if ($env: CMDER_DEBUG -and ($env: CMDER_DEBUG -match ' ^(1|true)$' )) {
32+ $DebugPreference = ' Continue'
33+ $VerbosePreference = ' Continue'
34+ }
35+
3936# Add Cmder modules directory to the autoload path.
4037$CmderModulePath = Join-path $PSScriptRoot " psmodules/"
4138
@@ -48,17 +45,26 @@ if (-not $moduleInstallerAvailable -and -not $env:PSModulePath.Contains($CmderMo
4845 $env: PSModulePath = $env: PSModulePath.Insert (0 , " $CmderModulePath ;" )
4946}
5047
48+ if ($ENV: CMDER_USER_CONFIG ) {
49+ Write-Verbose " CMDER IS ALSO USING INDIVIDUAL USER CONFIG FROM '$ENV: CMDER_USER_CONFIG '!"
50+ }
51+
5152# Read vendored Git Version
52- $gitVersionVendor = Get-GitVersion - GitPath " $ENV: CMDER_ROOT \vendor\git-for-windows\cmd"
53- Write-Debug " GIT VENDOR: ${gitVersionVendor} "
53+ $gitVendorPath = Join-Path $ENV: CMDER_ROOT ' vendor\git-for-windows\cmd'
54+ $gitVersionVendor = Get-GitVersion - GitPath $gitVendorPath
55+ if (-not [string ]::IsNullOrEmpty($gitVersionVendor )) {
56+ Write-Debug " GIT VENDOR: ${gitVersionVendor} "
57+ } else {
58+ Write-Debug " GIT VENDOR is not present at '$gitVendorPath '"
59+ }
5460
5561# Get user installed Git version(s) if found, and compare them with vendored version.
5662foreach ($git in (Get-Command - ErrorAction SilentlyContinue ' git' )) {
57- Write-Debug " GIT PATH: { $ git .Path} "
63+ Write-Debug " GIT USER PATH: $ ( $ git.Path ) "
5864 $gitDir = Split-Path - Path $git.Path
5965 $gitDir = Get-GitShimPath - GitPath $gitDir
6066 $gitVersionUser = Get-GitVersion - GitPath $gitDir
61- Write-Debug " GIT USER: ${gitVersionUser} "
67+ Write-Debug " GIT USER VERSION : ${gitVersionUser} "
6268
6369 $useGitVersion = Compare-GitVersion - UserVersion $gitVersionUser - VendorVersion $gitVersionVendor
6470 Write-Debug " Using Git Version: ${useGitVersion} "
@@ -102,18 +108,18 @@ if (Get-Command -Name "vim" -ErrorAction SilentlyContinue) {
102108if (Get-Module PSReadline - ErrorAction " SilentlyContinue" ) {
103109 # Display an extra prompt line between the prompt and the command input
104110 Set-PSReadlineOption - ExtraPromptLineCount 1
105-
111+
106112 # Invoked when Enter is pressed to submit a command
107113 if ($env: WT_SESSION ) {
108114 Set-PSReadLineKeyHandler - Key Enter - ScriptBlock {
109115 # Get the current command line
110116 $line = $null
111117 $cursor = $null
112118 [Microsoft.PowerShell.PSConsoleReadLine ]::GetBufferState([ref ]$line , [ref ]$cursor )
113-
119+
114120 # Accept the line first
115121 [Microsoft.PowerShell.PSConsoleReadLine ]::AcceptLine()
116-
122+
117123 # Emit OSC 133;C to mark start of command output
118124 # This is written directly to the console after the command is accepted
119125 [Console ]::Write(" $ ( [char ]0x1B ) ]133;C$ ( [char ]7 ) " )
@@ -224,28 +230,28 @@ if ( $(Get-Command prompt).Definition -match 'PS \$\(\$executionContext.SessionS
224230 [ScriptBlock ]$Prompt = {
225231 $lastSUCCESS = $?
226232 $realLastExitCode = $LastExitCode
227-
233+
228234 # Terminal-specific escape sequences for Windows Terminal and ConEmu
229235 if ($env: WT_SESSION -or $env: ConEmuPID ) {
230236 # Emit OSC 133;D to mark the end of command execution with exit code
231237 if ($env: WT_SESSION ) {
232238 Microsoft.PowerShell.Utility\Write-Host - NoNewline " $ ( [char ]0x1B ) ]133;D;$realLastExitCode $ ( [char ]7 ) "
233239 }
234-
240+
235241 # Emit OSC 9;9 to enable directory tracking
236242 # Enables "Duplicate Tab" and "Split Pane" to preserve the working directory
237243 $loc = $executionContext.SessionState.Path.CurrentLocation
238244 if ($loc.Provider.Name -eq " FileSystem" ) {
239245 Microsoft.PowerShell.Utility\Write-Host - NoNewline " $ ( [char ]0x1B ) ]9;9;`" $ ( $loc.ProviderPath ) `" $ ( [char ]0x1B ) \"
240246 }
241-
247+
242248 # Emit OSC 133;A to mark the start of the prompt
243249 # Enables features like command navigation, selection, and visual separators
244250 if ($env: WT_SESSION ) {
245251 Microsoft.PowerShell.Utility\Write-Host - NoNewline " $ ( [char ]0x1B ) ]133;A$ ( [char ]7 ) "
246252 }
247253 }
248-
254+
249255 $host.UI.RawUI.WindowTitle = Microsoft.PowerShell.Management\Split-Path $pwd.ProviderPath - Leaf
250256 Microsoft.PowerShell.Utility\Write-Host - NoNewline " $ ( [char ]0x200B ) `r $ ( [char ]0x1B ) [K"
251257 if ($lastSUCCESS -or ($LastExitCode -ne 0 )) {
@@ -254,12 +260,12 @@ if ( $(Get-Command prompt).Definition -match 'PS \$\(\$executionContext.SessionS
254260 PrePrompt | Microsoft.PowerShell.Utility\Write-Host - NoNewline
255261 CmderPrompt
256262 PostPrompt | Microsoft.PowerShell.Utility\Write-Host - NoNewline
257-
263+
258264 # Emit OSC 133;B to mark the start of command input (after prompt, before user types)
259265 if ($env: WT_SESSION ) {
260266 Microsoft.PowerShell.Utility\Write-Host - NoNewline " $ ( [char ]0x1B ) ]133;B$ ( [char ]7 ) "
261267 }
262-
268+
263269 $global :LastExitCode = $realLastExitCode
264270 return " "
265271 }
0 commit comments