55if ($Global :OhMyPoshProfileLoaded ) { return }
66$Global :OhMyPoshProfileLoaded = $true
77
8- # Performance: Only load modules if they're available
8+ # Performance: Suppress errors during module loading
99$ErrorActionPreference = ' SilentlyContinue'
1010
11+ # Import pre-installed modules (installed during Docker build)
12+ # Terminal-Icons: Provides file/folder icons in terminal listings
13+ # PSReadLine: Enhanced command-line editing experience with predictive IntelliSense
14+ Import-Module Terminal- Icons - ErrorAction SilentlyContinue
15+ Import-Module PSReadLine - ErrorAction SilentlyContinue
16+
17+ # Configure PSReadLine for enhanced experience (if available)
18+ if (Get-Module PSReadLine) {
19+ Set-PSReadLineOption - PredictionSource History - ErrorAction SilentlyContinue
20+ Set-PSReadLineOption - PredictionViewStyle ListView - ErrorAction SilentlyContinue
21+ }
22+
1123# Oh My Posh initialization with environment variable support
1224# Environment Variables:
1325# ENABLE_OHMYPOSH - Set to 'false' or '0' to disable Oh My Posh
1426# OHMYPOSH_THEME - Theme name (e.g., 'atomic') or URL to custom theme
1527# If empty, uses embedded Blue PSL 10K theme
1628
17- # Check if Oh My Posh is disabled via environment variable
18- if ($env: ENABLE_OHMYPOSH -eq ' false' -or $env: ENABLE_OHMYPOSH -eq ' 0' ) {
19- Write-Host " ℹ️ Oh My Posh disabled via ENABLE_OHMYPOSH environment variable" - ForegroundColor Cyan
20- } else {
29+ # Initialize Oh My Posh (unless disabled)
30+ if ($env: ENABLE_OHMYPOSH -ne ' false' -and $env: ENABLE_OHMYPOSH -ne ' 0' ) {
2131 $ohmyposhPath = ' /usr/local/bin/oh-my-posh'
2232 $embeddedTheme = ' /home/coder/.config/powershell/ohmyposh-container.json'
2333
2434 if (Test-Path $ohmyposhPath ) {
25- $themeConfig = $null
26- $themeName = ' Blue PSL 10K (embedded)'
27- $isFallback = $false
35+ $themeConfig = $embeddedTheme
2836
2937 # Determine theme configuration based on OHMYPOSH_THEME environment variable
3038 if ($env: OHMYPOSH_THEME ) {
3139 if ($env: OHMYPOSH_THEME -match ' ^https?://' ) {
3240 # Full URL provided - use as-is
3341 $themeConfig = $env: OHMYPOSH_THEME
34- $themeName = ' Custom URL theme'
3542 } else {
3643 # Theme name provided - construct URL to Oh My Posh built-in themes
3744 $themeConfig = " https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/$ ( $env: OHMYPOSH_THEME ) .omp.json"
38- $themeName = " $ ( $env: OHMYPOSH_THEME ) (built-in)"
3945 }
40- } else {
41- # Default: Use embedded Blue PSL 10K theme (works offline)
42- $themeConfig = $embeddedTheme
4346 }
4447
4548 # Try to initialize Oh My Posh with selected theme
46- $initSuccess = $false
4749 try {
4850 $initScript = & $ohmyposhPath init pwsh -- config $themeConfig 2>&1
4951 if ($initScript -and $LASTEXITCODE -eq 0 ) {
5052 Invoke-Expression $initScript
51- $initSuccess = $true
52- Write-Host " ✅ Oh My Posh loaded: $themeName " - ForegroundColor Green
53- } else {
54- throw " Init script failed or empty"
55- }
56- } catch {
57- # Fallback to embedded Blue PSL 10K theme if custom theme failed
58- if ($themeConfig -ne $embeddedTheme -and (Test-Path $embeddedTheme )) {
59- Write-Host " ⚠️ Theme '$themeName ' failed, falling back to Blue PSL 10K..." - ForegroundColor Yellow
60- try {
61- $initScript = & $ohmyposhPath init pwsh -- config $embeddedTheme 2>&1
62- if ($initScript -and $LASTEXITCODE -eq 0 ) {
63- Invoke-Expression $initScript
64- $initSuccess = $true
65- $isFallback = $true
66- Write-Host " ✅ Oh My Posh loaded: Blue PSL 10K (fallback)" - ForegroundColor Green
67- }
68- } catch {
69- # Fallback failed too
53+ } elseif ($themeConfig -ne $embeddedTheme -and (Test-Path $embeddedTheme )) {
54+ # Fallback to embedded theme if custom theme failed
55+ $initScript = & $ohmyposhPath init pwsh -- config $embeddedTheme 2>&1
56+ if ($initScript -and $LASTEXITCODE -eq 0 ) {
57+ Invoke-Expression $initScript
7058 }
7159 }
72-
73- if (-not $initSuccess ) {
74- Write-Host " ⚠️ Oh My Posh initialization failed: $ ( $_.Exception.Message ) " - ForegroundColor Yellow
75- Write-Host " Using basic PowerShell prompt" - ForegroundColor Gray
76- }
60+ } catch {
61+ # Silent failure - Oh My Posh initialization failed, continue with basic prompt
7762 }
78- } else {
79- Write-Host " ⚠️ Oh My Posh not found at $ohmyposhPath , using basic prompt" - ForegroundColor Yellow
8063 }
8164}
8265
@@ -102,13 +85,5 @@ function Show-ContainerInfo {
10285# Alias for container info
10386Set-Alias - Name info - Value Show-ContainerInfo
10487
105- # Welcome message (only show once)
106- if (-not $Global :OhMyPoshWelcomeShown ) {
107- $Global :OhMyPoshWelcomeShown = $true
108- Write-Host " `n 🚀 Enhanced PowerShell Container Ready!" - ForegroundColor Green
109- Write-Host " Type 'info' to see container details" - ForegroundColor Gray
110- Write-Host " Environment variables: ENABLE_OHMYPOSH, OHMYPOSH_THEME" - ForegroundColor Gray
111- }
112-
11388# Reset error preference
11489$ErrorActionPreference = ' Continue'
0 commit comments