-
Notifications
You must be signed in to change notification settings - Fork 1
/
pwshrc.ps1
68 lines (53 loc) · 1.97 KB
/
pwshrc.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
$env:PWSH_REPO = $env:PWSH_REPO ?? (Split-Path -Parent $MyInvocation.MyCommand.Definition)
function Invoke-EnvironmentVariables() {
$env:PWSH_CONFIG_DIR = $IsWindows `
? (Join-Path $env:LOCALAPPDATA pwsh) `
: (Join-Path $HOME .config pwsh)
$env:PWSH_HOME = $env:PWSH_HOME ?? (Join-Path $HOME pwsh)
$env:PWSH_CACHE = $env:PWSH_CACHE ?? (Join-Path $HOME .cache pwsh)
$env:PWSH_CONFIG = $env:PWSH_CONFIG ?? (Join-Path $env:PWSH_CONFIG_DIR pwsh.yaml)
$env:EDITOR = $env:EDITOR ?? 'nvim'
$env:HOME = $env:HOME ?? $env:USERPROFILE
}
function Invoke-EnsureEssentialDirectories {
@($env:PWSH_HOME, $env:PWSH_CACHE) | ForEach-Object {
if (!(Test-Path $_)) {
New-Item -ItemType Directory -Path $_ -Force | Out-Null
}
}
}
function Invoke-Core {
# Load the core modules
Get-ChildItem (Join-Path $env:PWSH_REPO modules\Core\*.psm1) -File `
| ForEach-Object { Import-Module $_.FullName }
}
function Invoke-Modules($config) {
# Get disabled module names
$disabledModules = $config.modules.PSObject.Properties `
| Where-Object { $_.Value.disabled } `
| Select-Object -ExpandProperty Name
# Load enabled feature modules
Get-ChildItem (Join-Path $env:PWSH_REPO modules) -Directory `
| Where-Object { !($_.Name -eq "Core") -and !($_.Name -in $disabledModules) } `
| ForEach-Object { Get-ChildItem "$($_.FullName)\*.psm1" } `
| ForEach-Object { Import-Module $_.FullName }
}
function Invoke-Path($config) {
$path = $env:Path.Split(";") | Where-Object { $_ } | Select-Object -Unique
$path += $config.paths
$env:Path = [string]::Join(";", $path)
}
# Load environment variables
Invoke-EnvironmentVariables
# Ensure essential dirs exist
Invoke-EnsureEssentialDirectories
# Load core modules
Invoke-Core
# Get config
$config = Get-Config
# Load modules
Invoke-Modules $config
# Update PATH
Invoke-Path $config
# Start prompt
Invoke-Prompt $config.modules?.Prompt?.config