mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-09 20:44:03 -08:00
parent
c8c027301d
commit
597a2a0d96
|
@ -56,6 +56,11 @@ Make sure to install fonts system wide to avoid seeing rectangles in your termin
|
|||
|
||||
### 2. Download the latest binary
|
||||
|
||||
:::info PowerShell
|
||||
There's a [PowerShell module][powershell] that contains all of the functionality below and makes installation a breeze.
|
||||
If you're not looking to use Oh my Posh outside of PowerShell, have a look at the [module][powershell] rather than continue reading here.
|
||||
:::
|
||||
|
||||
<Tabs
|
||||
groupId="operating-systems"
|
||||
defaultValue="windows"
|
||||
|
@ -215,53 +220,10 @@ oh-my-posh --print-shell
|
|||
}>
|
||||
<TabItem value="powershell">
|
||||
|
||||
Edit `$PROFILE` in your preferred PowerShell version and add the following lines.
|
||||
Edit `$PROFILE` in your preferred PowerShell version and add the following line.
|
||||
|
||||
```powershell
|
||||
[ScriptBlock]$Prompt = {
|
||||
$lastCommandSuccess = $?
|
||||
$realLASTEXITCODE = $global:LASTEXITCODE
|
||||
$errorCode = 0
|
||||
if ($lastCommandSuccess -eq $false) {
|
||||
#native app exit code
|
||||
if ($realLASTEXITCODE -is [int] -and $realLASTEXITCODE -gt 0) {
|
||||
$errorCode = $realLASTEXITCODE
|
||||
}
|
||||
else {
|
||||
$errorCode = 1
|
||||
}
|
||||
}
|
||||
|
||||
$executionTime = -1
|
||||
$history = Get-History -ErrorAction Ignore -Count 1
|
||||
if ($null -ne $history -and $null -ne $history.EndExecutionTime -and $null -ne $history.StartExecutionTime) {
|
||||
$executionTime = ($history.EndExecutionTime - $history.StartExecutionTime).TotalMilliseconds
|
||||
}
|
||||
|
||||
$startInfo = New-Object System.Diagnostics.ProcessStartInfo
|
||||
$startInfo.FileName = "C:\tools\oh-my-posh.exe"
|
||||
$cleanPWD = $PWD.ProviderPath.TrimEnd("\")
|
||||
$startInfo.Arguments = "-config=""$env:USERPROFILE\.poshthemes\jandedobbeleer.omp.json"" -error=$errorCode -pwd=""$cleanPWD"" -execution-time=$executionTime"
|
||||
$startInfo.Environment["TERM"] = "xterm-256color"
|
||||
$startInfo.CreateNoWindow = $true
|
||||
$startInfo.StandardOutputEncoding = [System.Text.Encoding]::UTF8
|
||||
$startInfo.RedirectStandardOutput = $true
|
||||
$startInfo.UseShellExecute = $false
|
||||
if ($PWD.Provider.Name -eq 'FileSystem') {
|
||||
$startInfo.WorkingDirectory = $PWD.ProviderPath
|
||||
}
|
||||
$process = New-Object System.Diagnostics.Process
|
||||
$process.StartInfo = $startInfo
|
||||
$process.Start() | Out-Null
|
||||
$standardOut = $process.StandardOutput.ReadToEnd()
|
||||
$process.WaitForExit()
|
||||
$standardOut
|
||||
$global:LASTEXITCODE = $realLASTEXITCODE
|
||||
#remove temp variables
|
||||
Remove-Variable realLASTEXITCODE -Confirm:$false
|
||||
Remove-Variable lastCommandSuccess -Confirm:$false
|
||||
}
|
||||
Set-Item -Path Function:prompt -Value $Prompt -Force
|
||||
Invoke-Expression (oh-my-posh --init --shell pwsh --config ~/.poshthemes/jandedobbeleer.omp.json)
|
||||
```
|
||||
|
||||
Once added, reload your profile for the changes to take effect.
|
||||
|
|
Loading…
Reference in a new issue