-
-
Notifications
You must be signed in to change notification settings - Fork 0
Add PowerShell 7.6.4 with enhanced console configuration and Nerd Font support #24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| powershellVersion = "7.6.4" | ||
| powershellExe = "pwsh.exe" | ||
| powershellLaunchExe = "powershell.bat" | ||
| powershellConf = "config\Microsoft.PowerShell_profile.ps1" | ||
| powershellFont = "CaskaydiaMono NF" | ||
| powershellRows = "33" | ||
| powershellCols = "110" | ||
|
|
||
| bundleRelease = "@RELEASE_VERSION@" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| # Bearsampp PowerShell Profile | ||
| # This profile configures PowerShell with enhanced console features | ||
| # PowerShell 7+ includes PSReadLine by default for command-line editing | ||
|
|
||
| # Get the shell root directory | ||
| $SHELL_ROOT = Split-Path -Parent $PSScriptRoot | ||
|
|
||
| # Set environment variables for Oh My Posh | ||
| $env:POSH_ROOT = Join-Path $SHELL_ROOT "vendor\oh-my-posh" | ||
|
|
||
| # Set PowerShell module path to include bundled modules | ||
| $env:PSModulePath = (Join-Path $SHELL_ROOT "vendor\modules") + ";" + $env:PSModulePath | ||
|
|
||
| # Configure console to use Nerd Font (Cascadia Mono NF) | ||
| # This is required for Oh My Posh icons and glyphs to display correctly | ||
| # Note: Font configuration is handled by the launcher (powershell.bat) via registry. | ||
|
|
||
| # Initialize Oh My Posh with theme | ||
| $ohMyPoshExe = "$env:POSH_ROOT\posh-windows-amd64.exe" | ||
| $ohMyPoshTheme = "$env:POSH_ROOT\themes\paradox.omp.json" | ||
|
|
||
| if (Test-Path $ohMyPoshExe -PathType Leaf) { | ||
| & $ohMyPoshExe init pwsh --config $ohMyPoshTheme | Invoke-Expression | ||
| } | ||
|
|
||
| # Import Terminal-Icons for colorful file/folder icons | ||
| Import-Module Terminal-Icons -ErrorAction SilentlyContinue | ||
|
|
||
| # Set PowerShell options for better experience | ||
| if ($PSVersionTable.PSVersion.Major -ge 5) { | ||
| # Use a single call to Set-PSReadLineOption for speed if possible (not all options can be combined) | ||
| Set-PSReadLineOption -EditMode Windows -HistorySearchCursorMovesToEnd -MaximumHistoryCount 10000 -HistoryNoDuplicates | ||
| Set-PSReadLineOption -PredictionSource History -ErrorAction SilentlyContinue | ||
| Set-PSReadLineOption -Colors @{ | ||
| Command = 'Green' | ||
| Parameter = 'Gray' | ||
| String = 'DarkCyan' | ||
| } | ||
|
|
||
| # Key bindings | ||
| Set-PSReadLineKeyHandler -Key UpArrow -Function HistorySearchBackward | ||
| Set-PSReadLineKeyHandler -Key DownArrow -Function HistorySearchForward | ||
| Set-PSReadLineKeyHandler -Key Tab -Function MenuComplete | ||
| } | ||
|
|
||
| # Welcome message | ||
| # Only show banner in interactive ConsoleHost and not when running commands | ||
| if ($Host.Name -eq "ConsoleHost" -and $ExecutionContext.SessionState.LanguageMode -eq "FullLanguage" -and -not $MyInvocation.BoundParameters.ContainsKey('Command')) { | ||
| Write-Host "Bearsampp PowerShell" -ForegroundColor Cyan | ||
| Write-Host "Enhanced with PSReadLine, Oh My Posh, and Terminal-Icons" -ForegroundColor Gray | ||
| Write-Host "" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # Bearsampp PowerShell Configuration | ||
|
|
||
| ## Font Requirement | ||
|
|
||
| This PowerShell module requires a **Nerd Font** to display Oh My Posh icons and glyphs correctly. | ||
|
|
||
| ### Required Font | ||
| - **Font Name**: Cascadia Mono NF | ||
| - **Installation**: Should be installed system-wide via Bearsampp prerequisites | ||
|
|
||
| ### Configuring the Font | ||
|
|
||
| #### Windows Terminal (Recommended) | ||
| If using Windows Terminal, add this to your `settings.json`: | ||
|
|
||
| ```json | ||
| { | ||
| "profiles": { | ||
| "defaults": { | ||
| "font": { | ||
| "face": "Cascadia Mono NF", | ||
| "size": 10 | ||
| } | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| #### Windows Console Host (conhost.exe) | ||
| 1. Right-click the title bar → Properties | ||
| 2. Go to the Font tab | ||
| 3. Select "Cascadia Mono NF" from the font list | ||
| 4. Click OK | ||
|
|
||
| #### PowerShell Console | ||
| The font is automatically used if it's set as the default console font in Windows. | ||
|
|
||
| ## Files | ||
|
|
||
| - **Microsoft.PowerShell_profile.ps1** - Main PowerShell profile | ||
| - Configures PSReadLine (command-line editing) | ||
| - Initializes Oh My Posh with paradox theme | ||
| - Sets up history and key bindings | ||
| - Requires Cascadia Mono NF font for proper icon display | ||
|
|
||
| ## Environment Variables | ||
|
|
||
| The profile sets these environment variables: | ||
| - `POSH_ROOT` - Path to Oh My Posh installation | ||
| - `POSH_THEMES_PATH` - Path to Oh My Posh themes directory | ||
|
|
||
|
Comment on lines
+46
to
+51
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 4. Posh_themes_path not set config/README.md states the profile sets POSH_THEMES_PATH, but Microsoft.PowerShell_profile.ps1 never sets it, so users/scripts following the documentation will rely on an environment variable that doesn’t exist. This is a documentation/config mismatch introduced with the new 7.6.4 config docs. Agent Prompt
|
||
| ## Customization | ||
|
|
||
| ### Change Oh My Posh Theme | ||
| Edit the profile and change the theme file: | ||
| ```powershell | ||
| $ohMyPoshTheme = Join-Path $env:POSH_ROOT "themes\YOUR_THEME.omp.json" | ||
| ``` | ||
|
|
||
| Available themes are in `vendor/oh-my-posh/themes/` | ||
|
|
||
| ### Modify PSReadLine Settings | ||
| Edit the `Set-PSReadLineOption` calls in the profile to customize: | ||
| - Colors | ||
| - Key bindings | ||
| - History behavior | ||
| - Prediction settings | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,137 @@ | ||
| Add-Type -AssemblyName System.Drawing | ||
|
|
||
| $fontsSrc = $args[0] | ||
| $fontsDest = $args[1] | ||
|
|
||
| if (Test-Path $fontsSrc) { | ||
| if (-not (Test-Path $fontsDest)) { | ||
| try { | ||
| New-Item -ItemType Directory -Path $fontsDest -Force | Out-Null | ||
| } catch { | ||
| Write-Error "Failed to create fonts destination directory" | ||
| } | ||
| } | ||
|
|
||
| $fontFiles = @(Get-ChildItem -Path $fontsSrc -Include *.ttf, *.otf -Recurse) | ||
| if ($fontFiles.Count -eq 0) { | ||
| Write-Warning "No font files found in $fontsSrc" | ||
| exit 0 | ||
| } | ||
|
|
||
| # Fast Path: If there's only one font file, we can potentially skip expensive collection loading | ||
| # if we can determine the name simply. But for Nerd Fonts, the file name != family name often. | ||
|
|
||
| # Explicitly load and extract font names | ||
| $fc = New-Object System.Drawing.Text.PrivateFontCollection | ||
| foreach ($file in $fontFiles) { | ||
| try { | ||
| $fc.AddFontFile($file.FullName) | ||
| } catch { | ||
| Write-Warning ("Failed to load font file: " + $file.FullName) | ||
| } | ||
| } | ||
|
|
||
| if ($fc.Families.Count -eq 0) { | ||
| foreach ($file in $fontFiles) { | ||
| try { | ||
| $fileBytes = [System.IO.File]::ReadAllBytes($file.FullName) | ||
| $handle = [System.Runtime.InteropServices.GCHandle]::Alloc($fileBytes, 'Pinned') | ||
| $fc.AddMemoryFont($handle.AddrOfPinnedObject(), $fileBytes.Length) | ||
| $handle.Free() | ||
| } catch {} | ||
| } | ||
| } | ||
|
|
||
| if ($fc.Families.Count -eq 0) { | ||
| Write-Warning "No font families found in $fontsSrc" | ||
| exit 0 | ||
| } | ||
|
|
||
| $allNames = @($fc.Families | ForEach-Object { $_.Name } | Select-Object -Unique) | ||
| # Prefer Nerd Font Mono (NFM) or Mono variants for console | ||
| $detectedName = $allNames | Where-Object { $_ -match "NFM|NF|Mono" } | Select-Object -First 1 | ||
| $fallbackName = $allNames | Select-Object -First 1 | ||
|
|
||
| $regPath = "HKCU:\Software\Microsoft\Windows NT\CurrentVersion\Fonts" | ||
| if (-not (Test-Path $regPath)) { | ||
| New-Item -Path "HKCU:\Software\Microsoft\Windows NT\CurrentVersion" -Name "Fonts" -Force | Out-Null | ||
| } | ||
|
|
||
| $fontFiles | ForEach-Object { | ||
| $fontFile = $_.FullName | ||
| $destFile = Join-Path $fontsDest $_.Name | ||
|
|
||
| $fileFc = New-Object System.Drawing.Text.PrivateFontCollection | ||
| try { | ||
| $fileFc.AddFontFile($fontFile) | ||
| $internalName = $fileFc.Families[0].Name | ||
| } catch { | ||
| $internalName = $null | ||
| } | ||
|
|
||
| if ($internalName) { | ||
| $regValueName = "$internalName (TrueType)" | ||
| $currentRegValue = Get-ItemProperty -Path $regPath -Name $regValueName -ErrorAction SilentlyContinue | Select-Object -ExpandProperty $regValueName -ErrorAction SilentlyContinue | ||
|
|
||
| $needsInstall = $false | ||
| if (-not (Test-Path $destFile)) { | ||
| $needsInstall = $true | ||
| } else { | ||
| $srcFileItem = Get-Item $fontFile | ||
| $destFileItem = Get-Item $destFile | ||
| if ($srcFileItem.Length -ne $destFileItem.Length -or $srcFileItem.LastWriteTime -gt $destFileItem.LastWriteTime) { | ||
| $needsInstall = $true | ||
| } | ||
| } | ||
|
|
||
| if ($null -eq $currentRegValue -or ($currentRegValue -ne $destFile -and $currentRegValue -ne $_.Name)) { | ||
| $needsInstall = $true | ||
| } | ||
|
|
||
| if ($needsInstall) { | ||
| try { | ||
| Copy-Item $fontFile $destFile -Force | ||
| Set-ItemProperty -Path $regPath -Name $regValueName -Value $destFile -Force | ||
|
|
||
| $signature = @' | ||
| [DllImport("gdi32.dll", CharSet = CharSet.Auto)] | ||
| public static extern int AddFontResourceEx(string lpszFilename, uint fl, IntPtr res); | ||
| '@ | ||
| $gdi32 = Add-Type -MemberDefinition $signature -Name "Gdi32" -Namespace "Win32" -PassThru | ||
| $gdi32::AddFontResourceEx($destFile, 0, [IntPtr]::Zero) | Out-Null | ||
| } catch { | ||
| Write-Error "Failed to install font $internalName" | ||
| } | ||
|
Comment on lines
+96
to
+104
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Add-type redefined repeatedly register-fonts.ps1 defines the Win32.Gdi32 type via Add-Type inside the per-font install loop, so after the first font it can fail because the type already exists, skipping AddFontResourceEx for later fonts and emitting a misleading "Failed to install" error. This makes multi-font packages register inconsistently in the current session. Agent Prompt
|
||
| } | ||
| } | ||
| } | ||
|
|
||
| $finalName = if ($detectedName) { $detectedName } else { $fallbackName } | ||
| if ($finalName) { | ||
| # Ensure the font is also registered in Console\TrueTypeFont | ||
| $trueTypeFontKey = "HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console\TrueTypeFont" | ||
| if (-not (Test-Path $trueTypeFontKey)) { | ||
| New-Item -Path "HKCU:\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Console" -Name "TrueTypeFont" -Force | Out-Null | ||
| } | ||
| Set-ItemProperty -Path $trueTypeFontKey -Name "00" -Value $finalName -Force | ||
|
|
||
| $signature = @' | ||
| [DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] | ||
| public static extern IntPtr SendMessageTimeout(IntPtr hWnd, uint Msg, IntPtr wParam, string lParam, uint fuFlags, uint uTimeout, out IntPtr lpdwResult); | ||
| '@ | ||
| try { | ||
| $user32 = Add-Type -MemberDefinition $signature -Name "User32" -Namespace "Win32" -PassThru | ||
| $HWND_BROADCAST = [IntPtr]0xffff | ||
| $WM_SETTINGCHANGE = 0x001A | ||
| $SMTO_ABORTIFHUNG = 0x0002 | ||
| $result = [IntPtr]::Zero | ||
| $user32::SendMessageTimeout($HWND_BROADCAST, $WM_SETTINGCHANGE, [IntPtr]::Zero, "Fonts", $SMTO_ABORTIFHUNG, 1000, [ref]$result) | Out-Null | ||
| } catch {} | ||
|
|
||
| Write-Output $finalName | ||
| } else { | ||
| Write-Warning "No valid fonts detected in $fontsSrc" | ||
| } | ||
| } else { | ||
| Write-Error "Fonts source path does not exist: $fontsSrc" | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| oh_my_posh = https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/posh-windows-amd64.exe | ||
| oh_my_posh_theme = https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/main/themes/paradox.omp.json | ||
|
|
||
| # Cascadia Mono Nerd Font - Nerd Font required for Oh My Posh glyphs/icons in the terminal | ||
| # font_name - must be the windows system name for the font | ||
| oh_my_posh_font_name = "CaskaydiaMono NF" | ||
|
|
||
| # Terminal-Icons - PowerShell module for colorful file/folder icons | ||
| # Automatically downloads the latest version from PowerShell Gallery during build | ||
| terminal_icons = https://www.powershellgallery.com/api/v2/package/Terminal-Icons | ||
|
|
||
| # PSReadLine - Enhanced command-line editing with syntax highlighting, predictive IntelliSense, and history search | ||
| # Provides advanced editing features like multi-line editing, undo/redo, and customizable key bindings | ||
| # Automatically updated to the latest version from PowerShell Gallery during build process | ||
| # Note: PowerShell 7+ includes PSReadLine by default, but this ensures the latest version with newest features | ||
| psreadline = https://www.powershellgallery.com/api/v2/package/PSReadLine |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2. Unpinned oh my posh exe
🐞 Bug⛨ SecurityAgent Prompt
ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools