Skip to content

Commit d9542f8

Browse files
committed
[pwsh profile] Support script file order and add preferences.
Contributes to #1.
1 parent 6638b97 commit d9542f8

File tree

3 files changed

+28
-2
lines changed

3 files changed

+28
-2
lines changed

PowerShell/Profile/Common/.files

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
statements.ps1
2+
Get-Profile.ps1
3+
Get-StrictMode.ps1
4+
Import-BatchEnvironment.ps1
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Copyright (c) 2023 Matthias Wolf, Mawosoft.
2+
3+
Set-StrictMode -Version 3
4+
$ErrorActionPreference = 'Stop'
5+
6+
# One history across all hosts per user
7+
Set-PSReadLineOption -HistorySavePath (Join-Path (
8+
[System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::MyDocuments)
9+
) 'PowerShell\PSReadLine\AllHosts_history.txt' )
10+
# Can be toggled with F2.
11+
Set-PSReadLineOption -PredictionViewStyle ListView

PowerShell/Profile/newProfile.ps1

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,19 @@ function Get-SourceContent {
5151
[ValidateNotNullOrEmpty()]
5252
[string]$Path
5353
)
54-
# TODO Support a config file (e.g. '.filelist') to determine order and inclusions/exclusions.
55-
[FileInfo[]]$files = Get-ChildItem $Path -Filter '*.ps1'
54+
# '.files just lists all file names to include in the desired order.
55+
[string]$filelist = Join-Path $Path '.files'
56+
[FileInfo[]]$files = $null
57+
if (Test-Path $filelist -PathType Leaf) {
58+
$files = Get-Content $filelist |
59+
ForEach-Object { $_.Trim() } |
60+
Where-Object { -not [string]::IsNullOrEmpty($_) -and -not $_.StartsWith([char]'#') } |
61+
ForEach-Object { Join-Path -Path $Path $_ } |
62+
Get-Item
63+
}
64+
else {
65+
$files = Get-ChildItem $Path -Filter '*.ps1'
66+
}
5667
Write-Verbose 'Source Files:'
5768
$files | Out-String | Write-Verbose
5869
$files | Get-Content -Raw

0 commit comments

Comments
 (0)