Skip to content

Commit

Permalink
chore: add powershell module info
Browse files Browse the repository at this point in the history
resolves #252
  • Loading branch information
JanDeDobbeleer committed Dec 23, 2020
1 parent c8c0273 commit 317b3ec
Showing 1 changed file with 7 additions and 45 deletions.
52 changes: 7 additions & 45 deletions docs/docs/installation.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit 317b3ec

Please sign in to comment.