mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-11-09 20:44:03 -08:00
feat(pwsh): expose errorcode to transient prompt
This commit is contained in:
parent
217bd243d5
commit
e1a1febc79
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -241,3 +241,5 @@ $RECYCLE.BIN/
|
|||
cosign.key
|
||||
|
||||
*.omp.json.bak
|
||||
|
||||
__debug_bin
|
||||
|
|
1
.vscode/launch.json
vendored
1
.vscode/launch.json
vendored
|
@ -43,6 +43,7 @@
|
|||
"transient",
|
||||
"--config=${workspaceRoot}/themes/jandedobbeleer.omp.json",
|
||||
"--shell=pwsh",
|
||||
"--error=1"
|
||||
]
|
||||
},
|
||||
{
|
||||
|
|
|
@ -9,7 +9,6 @@ import (
|
|||
"io/ioutil"
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"oh-my-posh/regex"
|
||||
"os"
|
||||
"os/exec"
|
||||
|
@ -239,9 +238,8 @@ func (env *ShellEnvironment) resolveConfigPath() {
|
|||
if len(env.CmdFlags.Config) == 0 {
|
||||
env.CmdFlags.Config = fmt.Sprintf("https://raw.githubusercontent.com/JanDeDobbeleer/oh-my-posh/v%s/themes/default.omp.json", env.Version)
|
||||
}
|
||||
location, err := url.ParseRequestURI(env.CmdFlags.Config)
|
||||
if err == nil {
|
||||
env.getConfigPath(location.String())
|
||||
if strings.HasPrefix(env.CmdFlags.Config, "https://") {
|
||||
env.getConfigPath(env.CmdFlags.Config)
|
||||
return
|
||||
}
|
||||
// Cygwin path always needs the full path as we're on Windows but not really.
|
||||
|
|
|
@ -62,7 +62,7 @@ function global:Initialize-ModuleSupport {
|
|||
$omp = "::OMP::"
|
||||
$config, $cleanPWD, $cleanPSWD = Get-PoshContext
|
||||
if ($env:POSH_TRANSIENT -eq $true) {
|
||||
$standardOut = @(&$omp prompt print transient --pwd="$cleanPWD" --pswd="$cleanPSWD" --config="$config" 2>&1)
|
||||
$standardOut = @(&$omp prompt print transient --error="$global:ERRORCODE" --pwd="$cleanPWD" --pswd="$cleanPSWD" --execution-time="$global:EXECUTIONTIME" --config="$config" 2>&1)
|
||||
$standardOut -join "`n"
|
||||
$env:POSH_TRANSIENT = $false
|
||||
return
|
||||
|
@ -72,16 +72,16 @@ function global:Initialize-ModuleSupport {
|
|||
$standardOut -join "`n"
|
||||
return
|
||||
}
|
||||
$errorCode = 0
|
||||
$global:ERRORCODE = 0
|
||||
Initialize-ModuleSupport
|
||||
Set-PoshContext
|
||||
if ($lastCommandSuccess -eq $false) {
|
||||
#native app exit code
|
||||
if ($realLASTEXITCODE -is [int] -and $realLASTEXITCODE -gt 0) {
|
||||
$errorCode = $realLASTEXITCODE
|
||||
$global:ERRORCODE = $realLASTEXITCODE
|
||||
}
|
||||
else {
|
||||
$errorCode = 1
|
||||
$global:ERRORCODE = 1
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -94,14 +94,14 @@ function global:Initialize-ModuleSupport {
|
|||
}
|
||||
catch {}
|
||||
|
||||
$executionTime = -1
|
||||
$global:EXECUTIONTIME = -1
|
||||
$history = Get-History -ErrorAction Ignore -Count 1
|
||||
if ($null -ne $history -and $null -ne $history.EndExecutionTime -and $null -ne $history.StartExecutionTime -and $global:omp_lastHistoryId -ne $history.Id) {
|
||||
$executionTime = ($history.EndExecutionTime - $history.StartExecutionTime).TotalMilliseconds
|
||||
$global:EXECUTIONTIME = ($history.EndExecutionTime - $history.StartExecutionTime).TotalMilliseconds
|
||||
$global:omp_lastHistoryId = $history.Id
|
||||
}
|
||||
$terminalWidth = $Host.UI.RawUI.WindowSize.Width
|
||||
$standardOut = @(&$omp prompt print primary --error="$errorCode" --pwd="$cleanPWD" --pswd="$cleanPSWD" --execution-time="$executionTime" --stack-count="$stackCount" --config="$config" --terminal-width=$terminalWidth 2>&1)
|
||||
$standardOut = @(&$omp prompt print primary --error="$global:ERRORCODE" --pwd="$cleanPWD" --pswd="$cleanPSWD" --execution-time="$global:EXECUTIONTIME" --stack-count="$stackCount" --config="$config" --terminal-width=$terminalWidth 2>&1)
|
||||
# make sure PSReadLine knows we have a multiline prompt
|
||||
$extraLines = $standardOut.Count - 1
|
||||
if ($extraLines -gt 0) {
|
||||
|
|
|
@ -20,9 +20,6 @@ function prompt_ohmyposh_precmd() {
|
|||
eval "$(::OMP:: prompt print primary --config="$POSH_THEME" --error="$omp_last_error" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" --eval --shell=zsh)"
|
||||
unset omp_start_time
|
||||
unset omp_now
|
||||
unset omp_elapsed
|
||||
unset omp_last_error
|
||||
unset omp_stack_count
|
||||
}
|
||||
|
||||
function _install-omp-hooks() {
|
||||
|
@ -73,7 +70,7 @@ _posh-zle-line-init() {
|
|||
local -i ret=$?
|
||||
(( $+zle_bracketed_paste )) && print -r -n - $zle_bracketed_paste[2]
|
||||
|
||||
eval "$(::OMP:: prompt print transient --config="$POSH_THEME" --eval --shell=zsh)"
|
||||
eval "$(::OMP:: prompt print transient --error="$omp_last_error" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" --config="$POSH_THEME" --eval --shell=zsh)"
|
||||
zle .reset-prompt
|
||||
|
||||
# If we received EOT, we exit the shell
|
||||
|
|
Loading…
Reference in a new issue