Skip to content

Commit 223fa70

Browse files
committed
Add command line argument support and conditional window title setting to PowerShell launcher
1 parent 557ff1d commit 223fa70

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

bin/powershell7.5.4/config/Microsoft.PowerShell_profile.ps1

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,13 @@ $env:PSModulePath = (Join-Path $SHELL_ROOT "vendor\modules") + ";" + $env:PSModu
1414
# Configure console to use Nerd Font (CaskaydiaCove NF)
1515
# This is required for Oh My Posh icons and glyphs to display correctly
1616
try {
17-
# Set console font to CaskaydiaCove NF
18-
$Host.UI.RawUI.WindowTitle = "Bearsampp PowerShell Console"
17+
# Only set default title if one hasn't been set already
18+
# This allows the launcher to set custom titles per console type
19+
if ($Host.UI.RawUI.WindowTitle -eq "Administrator: C:\WINDOWS\system32\cmd.exe" -or
20+
$Host.UI.RawUI.WindowTitle -eq "C:\WINDOWS\system32\cmd.exe" -or
21+
$Host.UI.RawUI.WindowTitle -match "pwsh\.exe") {
22+
$Host.UI.RawUI.WindowTitle = "Bearsampp PowerShell Console"
23+
}
1924

2025
# Note: Font configuration is typically set in Windows Terminal settings.json
2126
# or via registry for Windows Console Host. The font should be installed system-wide.

bin/powershell7.5.4/powershell.bat

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
@echo off
22
REM Bearsampp PowerShell Launcher
33
REM This script launches PowerShell with the custom Bearsampp profile
4+
REM
5+
REM Usage: powershell.bat [--title "Title"] [--startingDirectory "Path"]
6+
REM --title - Optional: Window title
7+
REM --startingDirectory - Optional: Starting directory
48

5-
setlocal
9+
setlocal EnableDelayedExpansion
610

711
REM Get the directory where this script is located
812
set "SHELL_ROOT=%~dp0"
@@ -11,7 +15,34 @@ set "SHELL_ROOT=%SHELL_ROOT:~0,-1%"
1115
REM Set the custom profile path
1216
set "CUSTOM_PROFILE=%SHELL_ROOT%\config\Microsoft.PowerShell_profile.ps1"
1317

14-
REM Launch PowerShell with custom profile using dot-sourcing
15-
"%SHELL_ROOT%\pwsh.exe" -NoExit -NoProfile -Command ". '%CUSTOM_PROFILE%'"
18+
REM Default values
19+
set "WINDOW_TITLE=Bearsampp PowerShell Console"
20+
set "START_DIR=%CD%"
21+
22+
REM Parse command line arguments
23+
:parse_args
24+
if "%~1"=="" goto end_parse
25+
if /i "%~1"=="--title" (
26+
set "WINDOW_TITLE=%~2"
27+
shift
28+
shift
29+
goto parse_args
30+
)
31+
if /i "%~1"=="--startingDirectory" (
32+
set "START_DIR=%~2"
33+
shift
34+
shift
35+
goto parse_args
36+
)
37+
shift
38+
goto parse_args
39+
:end_parse
40+
41+
REM Build the PowerShell command
42+
set "PS_COMMAND=$Host.UI.RawUI.WindowTitle='!WINDOW_TITLE!'; Set-Location '!START_DIR!'; . '!CUSTOM_PROFILE!'"
43+
44+
REM Launch PowerShell with custom profile and parameters
45+
"%SHELL_ROOT%\pwsh.exe" -NoExit -NoProfile -Command "!PS_COMMAND!"
1646

1747
endlocal
48+
=======

0 commit comments

Comments
 (0)