-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
oh-my-posh-windows.ps1
84 lines (66 loc) · 2.89 KB
/
oh-my-posh-windows.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
param([switch]$VerboseSwitch = $false)
# $Verbose=$true -or $VerboseSwitch
$Verbose=$VerboseSwitch
# Write-Verbose "[$script] [$env:SnippetsInitialized] -not `$env:SnippetsInitialized: $(-not $env:SnippetsInitialized)" -Verbose:$Verbose
$script = $MyInvocation.MyCommand
if (-not $env:SnippetsInitialized) {
$fileInfo = New-Object System.IO.FileInfo (Get-Item $PSScriptRoot).FullName
$path = $fileInfo.Directory.FullName;
. $path/Snippets/_common.ps1;
Initialize-Snippets -Verbose:$Verbose
}
function Setup-OMP {
param([switch]$Verbose = $false)
if ($env:IsWindows -ieq 'true') {
try {
if ($PSVersionTable.PSEdition -ieq 'core') {
$powershell = 'pwsh'
}
else {
$powershell = 'pwsh'
}
$ohMyPosh = Get-Command oh-my-posh
if (-not $ohMyPosh) {
. scoop install 'https://github.com/JanDeDobbeleer/oh-my-posh/releases/latest/download/oh-my-posh.json'
$ohMyPosh = Get-Command oh-my-posh
}
if (-not $ohMyPosh) {
Write-Host 'Cannot find Oh-My-Posh and cannot install with scoop.'
}
else {
Write-Verbose "[$script] `$ohMyPosh: $($ohMyPosh.Source)" -Verbose:$Verbose
$ompFolder = [System.IO.Path]::GetDirectoryName($ohMyPosh.Source)
$env:ohMyPosh=$ohMyPosh.Source
Write-Verbose -Verbose:$Verbose -Message "(oh-my-posh --init --shell $powershell --config `"$PSScriptRoot\ninja.omp.json`" | Invoke-Expression)"
$log = (oh-my-posh --init --shell $powershell --config "$PSScriptRoot\ninja.omp.json" | Invoke-Expression)
if(-not $log -or $log.Length -eq 0) { $log = "Exit Code: $LASTEXITCODE" }
return "OH-MY-POSH startup: [$log]"
}
}
catch {
Write-Host $Error
}
finally {
Write-Verbose "[$script] Leaving..." -Verbose:$Verbose
$Verbose = $VerboseSwitch
}
} else {
$Verbose = $VerboseSwitch
return "Wrong Operating System."
}
}
function Execute-OMP {
$scriptBlock = { & (Get-Item $env:ohMyPosh) $args }
$result = Invoke-Command -Verbose:$Verbose -ScriptBlock $scriptBlock -ArgumentList $args
Write-Verbose -Verbose:$VerboseSwitch -Message "[Execute-OMP] `$result: [$result]"
return $result
}
if ($env:IsWindows -ieq 'true') {
$setupResult = Setup-OMP -Verbose:$Verbose
Write-Verbose -Verbose:$Verbose -Message "[$script] Setup-OMP: [$setupResult]"
Write-Verbose -Verbose:$Verbose -Message "[$script] `$env:ohMyPosh `$args: [$env:ohMyPosh $args]"
$alias = set-alias -Verbose:$Verbose -Scope Global -Description "Snippets: [ps] OH-MY-POSH" -Name posh -Value Execute-OMP -PassThru
return "Registered alias for OH-MY-POSH"
} else {
return "Wrong Operating System."
}