Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions bin/powershell7.6.8/bearsampp.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
powershellVersion = "7.6.8"
powershellExe = "pwsh.exe"
powershellLaunchExe = "powershell.bat"
powershellConf = "config\Microsoft.PowerShell_profile.ps1"
powershellFont = "CaskaydiaMono NF"
powershellRows = "33"
powershellCols = "110"

bundleRelease = "@RELEASE_VERSION@"
52 changes: 52 additions & 0 deletions bin/powershell7.6.8/config/Microsoft.PowerShell_profile.ps1
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 ""
}
67 changes: 67 additions & 0 deletions bin/powershell7.6.8/config/README.md
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

## 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
162 changes: 162 additions & 0 deletions bin/powershell7.6.8/config/register-fonts.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
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
}

$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

$installFailed = $false
foreach ($fontItem in $fontFiles) {
$fontFile = $fontItem.FullName
$destFile = Join-Path $fontsDest $fontItem.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 $fontItem.Name)) {
$needsInstall = $true
}

if ($needsInstall) {
$copiedFile = $false
$regSet = $false
try {
Copy-Item -LiteralPath $fontFile -Destination $destFile -Force -ErrorAction Stop
$copiedFile = $true
Set-ItemProperty -Path $regPath -Name $regValueName -Value $destFile -Force -ErrorAction Stop
$regSet = $true
if ($gdi32::AddFontResourceEx($destFile, 0, [IntPtr]::Zero) -eq 0) {
throw "AddFontResourceEx failed for font $internalName"
Comment thread
qodo-code-review[bot] marked this conversation as resolved.
Resolved
}
} catch {
if ($copiedFile -and (Test-Path $destFile)) {
try { Remove-Item -LiteralPath $destFile -Force -ErrorAction SilentlyContinue } catch {}
}
if ($regSet) {
try { Remove-ItemProperty -Path $regPath -Name $regValueName -ErrorAction SilentlyContinue } catch {}
}
$installFailed = $true
Write-Error "Failed to install font ${internalName}: $($_.Exception.Message)"
}
}
}
}

if ($installFailed) {
Write-Error "Font installation failed; keeping fallback font"
exit 1
}

$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
}
try {
Set-ItemProperty -Path $trueTypeFontKey -Name "00" -Value $finalName -Force -ErrorAction Stop
} catch {
Write-Error "Failed to register TrueType font ${finalName}: $($_.Exception.Message)"
exit 1
}

$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"
exit 1
}
} else {
Write-Error "Fonts source path does not exist: $fontsSrc"
}
16 changes: 16 additions & 0 deletions bin/powershell7.6.8/deps.properties
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
Loading