mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-01-14 12:48:04 -08:00
fix: powershell invocation
This commit is contained in:
parent
9c1bf12c82
commit
8155c4b232
|
@ -84,10 +84,30 @@ Edit `$PROFILE` in your preferred PowerShell version and add the following lines
|
|||
|
||||
```powershell
|
||||
[ScriptBlock]$Prompt = {
|
||||
$realLASTEXITCODE = $global:LASTEXITCODE
|
||||
& "C:\tools\oh-my-posh.exe" -config "~/downloadedtheme.json" -error $realLASTEXITCODE -pwd $PWD
|
||||
$global:LASTEXITCODE = $realLASTEXITCODE
|
||||
Remove-Variable realLASTEXITCODE -Confirm:$false
|
||||
$realLASTEXITCODE = $global:LASTEXITCODE
|
||||
if ($realLASTEXITCODE -isnot [int]) {
|
||||
$realLASTEXITCODE = 0
|
||||
}
|
||||
$startInfo = New-Object System.Diagnostics.ProcessStartInfo
|
||||
$startInfo.FileName = "C:\tools\oh-my-posh.exe"
|
||||
$config = $global:PoshSettings.Theme
|
||||
$startInfo.Arguments = "-config C:\Users\User\Downloads\downloadedtheme.json -pwd $PWD -error $realLASTEXITCODE"
|
||||
$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
|
||||
}
|
||||
$process = New-Object System.Diagnostics.Process
|
||||
$process.StartInfo = $startInfo
|
||||
$process.Start() | Out-Null
|
||||
$standardOut = $process.StandardOutput.ReadToEnd()
|
||||
$process.WaitForExit()
|
||||
$standardOut
|
||||
$global:LASTEXITCODE = $realLASTEXITCODE
|
||||
Remove-Variable realLASTEXITCODE -Confirm:$false
|
||||
}
|
||||
Set-Item -Path Function:prompt -Value $Prompt -Force
|
||||
```
|
||||
|
|
|
@ -122,7 +122,7 @@ func (e *engine) render() {
|
|||
for _, block := range e.settings.Blocks {
|
||||
// if line break, append a line break
|
||||
if block.Type == LineBreak {
|
||||
fmt.Print(e.renderer.lineBreak())
|
||||
fmt.Print("\n")
|
||||
continue
|
||||
}
|
||||
if block.VerticalOffset != 0 {
|
||||
|
|
|
@ -23,19 +23,6 @@ if (!$IsWindows) {
|
|||
$executable = Get-PoshCommand
|
||||
Invoke-Expression -Command "chmod +x $executable"
|
||||
}
|
||||
if ($IsWindows) {
|
||||
# When this is not set, outputted fonts aren't rendered correctly in some terminals for the prompt function
|
||||
# It can also fail when we're not running in a console (and then, well, you're on your own)
|
||||
try {
|
||||
[console]::OutputEncoding = New-Object System.Text.UTF8Encoding
|
||||
}
|
||||
catch {
|
||||
Write-Host "oh-my-posh: unable to set output encoding to UTF8, fonts might be rendered incorrectly."
|
||||
}
|
||||
# Not running it beforehand in the terminal will fail the prompt somehow
|
||||
$poshCommand = Get-PoshCommand
|
||||
& $poshCommand | Out-Null
|
||||
}
|
||||
|
||||
function Set-PoshContext {}
|
||||
|
||||
|
@ -58,10 +45,28 @@ function Set-PoshPrompt {
|
|||
|
||||
[ScriptBlock]$Prompt = {
|
||||
$realLASTEXITCODE = $global:LASTEXITCODE
|
||||
$poshCommand = Get-PoshCommand
|
||||
if ($realLASTEXITCODE -isnot [int]) {
|
||||
$realLASTEXITCODE = 0
|
||||
}
|
||||
$startInfo = New-Object System.Diagnostics.ProcessStartInfo
|
||||
$startInfo.FileName = Get-PoshCommand
|
||||
$config = $global:PoshSettings.Theme
|
||||
$startInfo.Arguments = "-config $config -pwd $PWD -error $realLASTEXITCODE"
|
||||
$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
|
||||
}
|
||||
$process = New-Object System.Diagnostics.Process
|
||||
$process.StartInfo = $startInfo
|
||||
Set-PoshContext
|
||||
& $poshCommand -config $config -error $realLASTEXITCODE -pwd $PWD
|
||||
$process.Start() | Out-Null
|
||||
$standardOut = $process.StandardOutput.ReadToEnd()
|
||||
$process.WaitForExit()
|
||||
$standardOut
|
||||
$global:LASTEXITCODE = $realLASTEXITCODE
|
||||
Remove-Variable realLASTEXITCODE -Confirm:$false
|
||||
}
|
||||
|
|
|
@ -130,13 +130,6 @@ func (r *Renderer) lenWithoutANSI(str string) int {
|
|||
return count
|
||||
}
|
||||
|
||||
func (r *Renderer) lineBreak() string {
|
||||
if r.shell == "pwsh" {
|
||||
return "\x1b[1000C "
|
||||
}
|
||||
return "\n"
|
||||
}
|
||||
|
||||
func (r *Renderer) carriageForward() string {
|
||||
return fmt.Sprintf(r.formats.left, 1000)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue