feat(pwsh): expose errorcode to transient prompt

This commit is contained in:
Jan De Dobbeleer 2022-03-24 07:25:29 +01:00 committed by Jan De Dobbeleer
parent 217bd243d5
commit e1a1febc79
5 changed files with 13 additions and 15 deletions

2
.gitignore vendored
View file

@ -241,3 +241,5 @@ $RECYCLE.BIN/
cosign.key cosign.key
*.omp.json.bak *.omp.json.bak
__debug_bin

1
.vscode/launch.json vendored
View file

@ -43,6 +43,7 @@
"transient", "transient",
"--config=${workspaceRoot}/themes/jandedobbeleer.omp.json", "--config=${workspaceRoot}/themes/jandedobbeleer.omp.json",
"--shell=pwsh", "--shell=pwsh",
"--error=1"
] ]
}, },
{ {

View file

@ -9,7 +9,6 @@ import (
"io/ioutil" "io/ioutil"
"log" "log"
"net/http" "net/http"
"net/url"
"oh-my-posh/regex" "oh-my-posh/regex"
"os" "os"
"os/exec" "os/exec"
@ -239,9 +238,8 @@ func (env *ShellEnvironment) resolveConfigPath() {
if len(env.CmdFlags.Config) == 0 { 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) 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 strings.HasPrefix(env.CmdFlags.Config, "https://") {
if err == nil { env.getConfigPath(env.CmdFlags.Config)
env.getConfigPath(location.String())
return return
} }
// Cygwin path always needs the full path as we're on Windows but not really. // Cygwin path always needs the full path as we're on Windows but not really.

View file

@ -62,7 +62,7 @@ function global:Initialize-ModuleSupport {
$omp = "::OMP::" $omp = "::OMP::"
$config, $cleanPWD, $cleanPSWD = Get-PoshContext $config, $cleanPWD, $cleanPSWD = Get-PoshContext
if ($env:POSH_TRANSIENT -eq $true) { 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" $standardOut -join "`n"
$env:POSH_TRANSIENT = $false $env:POSH_TRANSIENT = $false
return return
@ -72,16 +72,16 @@ function global:Initialize-ModuleSupport {
$standardOut -join "`n" $standardOut -join "`n"
return return
} }
$errorCode = 0 $global:ERRORCODE = 0
Initialize-ModuleSupport Initialize-ModuleSupport
Set-PoshContext Set-PoshContext
if ($lastCommandSuccess -eq $false) { if ($lastCommandSuccess -eq $false) {
#native app exit code #native app exit code
if ($realLASTEXITCODE -is [int] -and $realLASTEXITCODE -gt 0) { if ($realLASTEXITCODE -is [int] -and $realLASTEXITCODE -gt 0) {
$errorCode = $realLASTEXITCODE $global:ERRORCODE = $realLASTEXITCODE
} }
else { else {
$errorCode = 1 $global:ERRORCODE = 1
} }
} }
@ -94,14 +94,14 @@ function global:Initialize-ModuleSupport {
} }
catch {} catch {}
$executionTime = -1 $global:EXECUTIONTIME = -1
$history = Get-History -ErrorAction Ignore -Count 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) { 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 $global:omp_lastHistoryId = $history.Id
} }
$terminalWidth = $Host.UI.RawUI.WindowSize.Width $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 # make sure PSReadLine knows we have a multiline prompt
$extraLines = $standardOut.Count - 1 $extraLines = $standardOut.Count - 1
if ($extraLines -gt 0) { if ($extraLines -gt 0) {

View file

@ -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)" 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_start_time
unset omp_now unset omp_now
unset omp_elapsed
unset omp_last_error
unset omp_stack_count
} }
function _install-omp-hooks() { function _install-omp-hooks() {
@ -73,7 +70,7 @@ _posh-zle-line-init() {
local -i ret=$? local -i ret=$?
(( $+zle_bracketed_paste )) && print -r -n - $zle_bracketed_paste[2] (( $+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 zle .reset-prompt
# If we received EOT, we exit the shell # If we received EOT, we exit the shell