-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMicrosoft.PowerShell_profile.ps1
More file actions
57 lines (50 loc) · 2.39 KB
/
Microsoft.PowerShell_profile.ps1
File metadata and controls
57 lines (50 loc) · 2.39 KB
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
. (Join-Path -Path $PSScriptRoot -ChildPath ProfileCommon.ps1)
# oh-my-posh v3
# This will run every time the prompt displays so it's important to keep it fast.
function Set-PromptContext {
# Enable the git segment to indicate if pre-commit is installed.
if (Get-Command git -ErrorAction SilentlyContinue) {
$repoRoot = git rev-parse --show-toplevel 2>&1
if ($LASTEXITCODE -eq 0) {
$preCommitHook = Test-Path (Join-Path $repoRoot '.git' 'hooks' 'pre-commit')
$env:PRE_COMMIT_INSTALLED = @{ $true = '✓'; $false = '' }[$preCommitHook]
}
}
# Enable the pushd/popd stack depth to be displayed.
$stackDepth = (Get-Location -Stack).Count
$env:LOCATION_STACK_DEPTH = @{ $true = ''; $false = "$stackDepth" }[0 -eq $stackDepth]
}
Write-ProfileLog 'oh-my-posh initialization'
if ($null -ne (Get-Command 'oh-my-posh' -ErrorAction Ignore)) {
oh-my-posh init pwsh --config $PSScriptRoot/themes/illig.json | Invoke-Expression
New-Alias -Name 'Set-PromptContext' -Value 'Set-PromptContext' -Scope Global
}
else {
Write-Warning 'oh-my-posh not detected. Install to get the prompt: https://ohmyposh.dev/docs/'
Write-Warning 'Falling back to script-based prompt. This is much slower than oh-my-posh.'
Enable-ScriptBasedPrompt
}
Write-ProfileLog 'oh-my-posh initialization complete'
# Enable iTerm2 integration if running in iTerm2. This allows iTerm2 to show the
# current directory and remote host in the title bar. Must be done after
# oh-my-posh is initialized to ensure the prompt function is defined, but also
# to ensure the console output isn't captured/redirected by the prompt function.
# This is a bit hacky but iTerm2 doesn't provide a better way to do this.
if ($env:TERM_PROGRAM -eq 'iTerm.app') {
$Global:__iterm2OriginalPrompt = $function:prompt
function Global:prompt {
# Report current context to iTerm2
$dir = $PWD.ProviderPath
[Console]::Write("`e]1337;CurrentDir=$dir`a")
[Console]::Write("`e]1337;RemoteHost=$env:USER@$(hostname)`a")
# Call the original prompt (oh-my-posh or whatever is configured)
if ($Global:__iterm2OriginalPrompt) {
& $Global:__iterm2OriginalPrompt
}
}
}
$ChocolateyProfile = "$env:ChocolateyInstall\helpers\chocolateyProfile.psm1"
if (Test-Path($ChocolateyProfile)) {
Import-Module "$ChocolateyProfile"
}
Complete-ProfileDiagnostics