mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-02 05:41:10 -08:00
fix(shell): prioritize $?
for consistent status in Bash/Zsh
This commit is contained in:
parent
9f2c6d1df5
commit
7f418d7c2d
|
@ -35,7 +35,7 @@ function _omp_start_timer() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function _omp_ftcs_command_start() {
|
function _omp_ftcs_command_start() {
|
||||||
if [ "::FTCS_MARKS::" == "true" ]; then
|
if [[ "::FTCS_MARKS::" == "true" ]]; then
|
||||||
printf "\e]133;C\a"
|
printf "\e]133;C\a"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -55,12 +55,15 @@ function _omp_hook() {
|
||||||
local omp_elapsed=-1
|
local omp_elapsed=-1
|
||||||
local no_exit_code="true"
|
local no_exit_code="true"
|
||||||
|
|
||||||
if [[ -n "$omp_start_time" ]]; then
|
if [[ "$omp_start_time" ]]; then
|
||||||
local omp_now=$(::OMP:: get millis --shell=bash)
|
local omp_now=$(::OMP:: get millis --shell=bash)
|
||||||
omp_elapsed=$((omp_now-omp_start_time))
|
omp_elapsed=$((omp_now - omp_start_time))
|
||||||
omp_start_time=""
|
omp_start_time=""
|
||||||
no_exit_code="false"
|
no_exit_code="false"
|
||||||
fi
|
fi
|
||||||
|
if [[ "${pipeStatus[-1]}" != "$ret" ]]; then
|
||||||
|
pipeStatus=("$ret")
|
||||||
|
fi
|
||||||
|
|
||||||
set_poshcontext
|
set_poshcontext
|
||||||
_set_posh_cursor_position
|
_set_posh_cursor_position
|
||||||
|
@ -69,11 +72,11 @@ function _omp_hook() {
|
||||||
return $ret
|
return $ret
|
||||||
}
|
}
|
||||||
|
|
||||||
if [ "$TERM" != "linux" ] && [ -x "$(command -v ::OMP::)" ] && ! [[ "$PROMPT_COMMAND" =~ "_omp_hook" ]]; then
|
if [[ "$TERM" != "linux" ]] && [[ -x "$(command -v ::OMP::)" ]] && ! [[ "$PROMPT_COMMAND" =~ "_omp_hook" ]]; then
|
||||||
PROMPT_COMMAND="_omp_hook; $PROMPT_COMMAND"
|
PROMPT_COMMAND="_omp_hook; $PROMPT_COMMAND"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ "::UPGRADE::" == "true" ]; then
|
if [[ "::UPGRADE::" == "true" ]]; then
|
||||||
echo "::UPGRADENOTICE::"
|
echo "::UPGRADENOTICE::"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ function _set_posh_cursor_position() {
|
||||||
# not supported in Midnight Commander
|
# not supported in Midnight Commander
|
||||||
# see https://github.com/JanDeDobbeleer/oh-my-posh/issues/3415
|
# see https://github.com/JanDeDobbeleer/oh-my-posh/issues/3415
|
||||||
if [[ "::CURSOR::" != "true" ]] || [[ -v MC_SID ]]; then
|
if [[ "::CURSOR::" != "true" ]] || [[ -v MC_SID ]]; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
local oldstty=$(stty -g)
|
local oldstty=$(stty -g)
|
||||||
|
@ -44,7 +44,8 @@ function prompt_ohmyposh_preexec() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function prompt_ohmyposh_precmd() {
|
function prompt_ohmyposh_precmd() {
|
||||||
omp_last_error=$? pipeStatus=(${pipestatus[@]})
|
omp_last_error=$?
|
||||||
|
local pipeStatus=(${pipestatus[@]})
|
||||||
omp_stack_count=${#dirstack[@]}
|
omp_stack_count=${#dirstack[@]}
|
||||||
omp_elapsed=-1
|
omp_elapsed=-1
|
||||||
no_exit_code="true"
|
no_exit_code="true"
|
||||||
|
@ -53,6 +54,9 @@ function prompt_ohmyposh_precmd() {
|
||||||
omp_elapsed=$(($omp_now-$omp_start_time))
|
omp_elapsed=$(($omp_now-$omp_start_time))
|
||||||
no_exit_code="false"
|
no_exit_code="false"
|
||||||
fi
|
fi
|
||||||
|
if [[ "${pipeStatus[-1]}" != "$omp_last_error" ]]; then
|
||||||
|
pipeStatus=("$omp_last_error")
|
||||||
|
fi
|
||||||
count=$((POSH_PROMPT_COUNT+1))
|
count=$((POSH_PROMPT_COUNT+1))
|
||||||
export POSH_PROMPT_COUNT=$count
|
export POSH_PROMPT_COUNT=$count
|
||||||
set_poshcontext
|
set_poshcontext
|
||||||
|
@ -67,8 +71,8 @@ add-zsh-hook precmd prompt_ohmyposh_precmd
|
||||||
add-zsh-hook preexec prompt_ohmyposh_preexec
|
add-zsh-hook preexec prompt_ohmyposh_preexec
|
||||||
|
|
||||||
# perform cleanup so a new initialization in current session works
|
# perform cleanup so a new initialization in current session works
|
||||||
if [[ "$(zle -lL self-insert)" = *"_posh-tooltip"* ]]; then
|
if [[ "$(bindkey " ")" = *"_posh-tooltip"* ]]; then
|
||||||
zle -N self-insert
|
bindkey " " self-insert
|
||||||
fi
|
fi
|
||||||
if [[ "$(zle -lL zle-line-init)" = *"_posh-zle-line-init"* ]]; then
|
if [[ "$(zle -lL zle-line-init)" = *"_posh-zle-line-init"* ]]; then
|
||||||
zle -N zle-line-init
|
zle -N zle-line-init
|
||||||
|
@ -76,7 +80,7 @@ fi
|
||||||
|
|
||||||
function _posh-tooltip() {
|
function _posh-tooltip() {
|
||||||
# https://github.com/zsh-users/zsh-autosuggestions - clear suggestion to avoid keeping it after the newly inserted space
|
# https://github.com/zsh-users/zsh-autosuggestions - clear suggestion to avoid keeping it after the newly inserted space
|
||||||
if [[ -n "$(zle -lL autosuggest-clear)" ]]; then
|
if [[ "$(zle -lL autosuggest-clear)" ]]; then
|
||||||
# only if suggestions not disabled (variable not set)
|
# only if suggestions not disabled (variable not set)
|
||||||
if ! [[ -v _ZSH_AUTOSUGGEST_DISABLED ]]; then
|
if ! [[ -v _ZSH_AUTOSUGGEST_DISABLED ]]; then
|
||||||
zle autosuggest-clear
|
zle autosuggest-clear
|
||||||
|
@ -84,7 +88,7 @@ function _posh-tooltip() {
|
||||||
fi
|
fi
|
||||||
zle .self-insert
|
zle .self-insert
|
||||||
# https://github.com/zsh-users/zsh-autosuggestions - fetch new suggestion after the space
|
# https://github.com/zsh-users/zsh-autosuggestions - fetch new suggestion after the space
|
||||||
if [[ -n "$(zle -lL autosuggest-fetch)" ]]; then
|
if [[ "$(zle -lL autosuggest-fetch)" ]]; then
|
||||||
# only if suggestions not disabled (variable not set)
|
# only if suggestions not disabled (variable not set)
|
||||||
if ! [[ -v _ZSH_AUTOSUGGEST_DISABLED ]]; then
|
if ! [[ -v _ZSH_AUTOSUGGEST_DISABLED ]]; then
|
||||||
zle autosuggest-fetch
|
zle autosuggest-fetch
|
||||||
|
@ -107,30 +111,30 @@ function _posh-tooltip() {
|
||||||
}
|
}
|
||||||
|
|
||||||
function _posh-zle-line-init() {
|
function _posh-zle-line-init() {
|
||||||
[[ $CONTEXT == start ]] || return 0
|
[[ $CONTEXT == start ]] || return 0
|
||||||
|
|
||||||
# Start regular line editor
|
# Start regular line editor.
|
||||||
(( $+zle_bracketed_paste )) && print -r -n - $zle_bracketed_paste[1]
|
(( $+zle_bracketed_paste )) && print -r -n - $zle_bracketed_paste[1]
|
||||||
zle .recursive-edit
|
zle .recursive-edit
|
||||||
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:: print transient --status="$omp_last_error" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" --config="$POSH_THEME" --eval --shell=zsh --shell-version="$ZSH_VERSION" --no-status="$no_exit_code")"
|
eval "$(::OMP:: print transient --status="$omp_last_error" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" --config="$POSH_THEME" --eval --shell=zsh --shell-version="$ZSH_VERSION" --no-status="$no_exit_code")"
|
||||||
zle .reset-prompt
|
zle .reset-prompt
|
||||||
|
|
||||||
# If we received EOT, we exit the shell
|
# Exit the shell if we receive EOT.
|
||||||
if [[ $ret == 0 && $KEYS == $'\4' ]]; then
|
if [[ $ret == 0 && $KEYS == $'\4' ]]; then
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Ctrl-C
|
if ((ret)); then
|
||||||
if (( ret )); then
|
# TODO (fix): this is not equal to sending a SIGINT, since the status code ($?) is set to 1 instead of 130.
|
||||||
zle .send-break
|
zle .send-break
|
||||||
else
|
else
|
||||||
# Enter
|
# Enter
|
||||||
zle .accept-line
|
zle .accept-line
|
||||||
fi
|
fi
|
||||||
return ret
|
return ret
|
||||||
}
|
}
|
||||||
|
|
||||||
function enable_poshtooltips() {
|
function enable_poshtooltips() {
|
||||||
|
@ -146,10 +150,10 @@ function enable_poshtransientprompt() {
|
||||||
bindkey '^[[F' end-of-line
|
bindkey '^[[F' end-of-line
|
||||||
bindkey '^[[H' beginning-of-line
|
bindkey '^[[H' beginning-of-line
|
||||||
_widgets=$(zle -la)
|
_widgets=$(zle -la)
|
||||||
if [[ -n "${_widgets[(r)down-line-or-beginning-search]}" ]]; then
|
if [[ "${_widgets[(r)down-line-or-beginning-search]}" ]]; then
|
||||||
bindkey '^[[B' down-line-or-beginning-search
|
bindkey '^[[B' down-line-or-beginning-search
|
||||||
fi
|
fi
|
||||||
if [[ -n "${_widgets[(r)up-line-or-beginning-search]}" ]]; then
|
if [[ "${_widgets[(r)up-line-or-beginning-search]}" ]]; then
|
||||||
bindkey '^[[A' up-line-or-beginning-search
|
bindkey '^[[A' up-line-or-beginning-search
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
@ -163,9 +167,9 @@ if [[ "::TRANSIENT::" = "true" ]]; then
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "::UPGRADE::" = "true" ]]; then
|
if [[ "::UPGRADE::" = "true" ]]; then
|
||||||
echo "::UPGRADENOTICE::"
|
echo "::UPGRADENOTICE::"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ "::AUTOUPGRADE::" = "true" ]]; then
|
if [[ "::AUTOUPGRADE::" = "true" ]]; then
|
||||||
::OMP:: upgrade
|
::OMP:: upgrade
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Reference in a new issue