mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-02 05:41:10 -08:00
feat(shell): restore line logic for zsh and bash
This commit is contained in:
parent
bc21ba3aef
commit
221b2d7d51
|
@ -9,6 +9,26 @@ PS0='${omp_start_time:0:$((omp_start_time="$(_omp_start_timer)",0))}'
|
||||||
# set secondary prompt
|
# set secondary prompt
|
||||||
PS2="$(::OMP:: print secondary --config="$POSH_THEME" --shell=bash --shell-version="$BASH_VERSION")"
|
PS2="$(::OMP:: print secondary --config="$POSH_THEME" --shell=bash --shell-version="$BASH_VERSION")"
|
||||||
|
|
||||||
|
function _set_posh_cursor_position() {
|
||||||
|
# not supported in Midnight Commander
|
||||||
|
# see https://github.com/JanDeDobbeleer/oh-my-posh/issues/3415
|
||||||
|
if [[ -v MC_SID ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
local oldstty=$(stty -g)
|
||||||
|
stty raw -echo min 0
|
||||||
|
|
||||||
|
local COL
|
||||||
|
local ROW
|
||||||
|
IFS=';' read -sdR -p $'\E[6n' ROW COL
|
||||||
|
|
||||||
|
stty $oldstty
|
||||||
|
|
||||||
|
export POSH_CURSOR_LINE=${ROW#*[}
|
||||||
|
export POSH_CURSOR_COLUMN=${COL}
|
||||||
|
}
|
||||||
|
|
||||||
function _omp_start_timer() {
|
function _omp_start_timer() {
|
||||||
::OMP:: get millis
|
::OMP:: get millis
|
||||||
}
|
}
|
||||||
|
@ -28,6 +48,7 @@ function _omp_hook() {
|
||||||
omp_start_time=""
|
omp_start_time=""
|
||||||
fi
|
fi
|
||||||
set_poshcontext
|
set_poshcontext
|
||||||
|
_set_posh_cursor_position
|
||||||
PS1="$(::OMP:: print primary --config="$POSH_THEME" --shell=bash --shell-version="$BASH_VERSION" --error="$ret" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" | tr -d '\0')"
|
PS1="$(::OMP:: print primary --config="$POSH_THEME" --shell=bash --shell-version="$BASH_VERSION" --error="$ret" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" | tr -d '\0')"
|
||||||
return $ret
|
return $ret
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,28 @@ export POSH_PROMPT_COUNT=0
|
||||||
# set secondary prompt
|
# set secondary prompt
|
||||||
PS2="$(::OMP:: print secondary --config="$POSH_THEME" --shell=zsh)"
|
PS2="$(::OMP:: print secondary --config="$POSH_THEME" --shell=zsh)"
|
||||||
|
|
||||||
|
function _set_posh_cursor_position() {
|
||||||
|
# not supported in Midnight Commander
|
||||||
|
# see https://github.com/JanDeDobbeleer/oh-my-posh/issues/3415
|
||||||
|
if [[ -v MC_SID ]]; then
|
||||||
|
return
|
||||||
|
fi
|
||||||
|
|
||||||
|
local oldstty=$(stty -g)
|
||||||
|
stty raw -echo min 0
|
||||||
|
|
||||||
|
local pos
|
||||||
|
echo -en "\033[6n" > /dev/tty
|
||||||
|
read -r -d R pos
|
||||||
|
pos=${pos:2} # strip off the esc-[
|
||||||
|
local parts=(${(s:;:)pos})
|
||||||
|
|
||||||
|
stty $oldstty
|
||||||
|
|
||||||
|
export POSH_CURSOR_LINE=${parts[1]}
|
||||||
|
export POSH_CURSOR_COLUMN=${parts[2]}
|
||||||
|
}
|
||||||
|
|
||||||
# template function for context loading
|
# template function for context loading
|
||||||
function set_poshcontext() {
|
function set_poshcontext() {
|
||||||
return
|
return
|
||||||
|
@ -27,6 +49,7 @@ function prompt_ohmyposh_precmd() {
|
||||||
count=$((POSH_PROMPT_COUNT+1))
|
count=$((POSH_PROMPT_COUNT+1))
|
||||||
export POSH_PROMPT_COUNT=$count
|
export POSH_PROMPT_COUNT=$count
|
||||||
set_poshcontext
|
set_poshcontext
|
||||||
|
_set_posh_cursor_position
|
||||||
eval "$(::OMP:: print primary --config="$POSH_THEME" --error="$omp_last_error" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" --eval --shell=zsh --shell-version="$ZSH_VERSION")"
|
eval "$(::OMP:: print primary --config="$POSH_THEME" --error="$omp_last_error" --execution-time="$omp_elapsed" --stack-count="$omp_stack_count" --eval --shell=zsh --shell-version="$ZSH_VERSION")"
|
||||||
unset omp_start_time
|
unset omp_start_time
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,8 +86,9 @@ Tells the engine what to do with the block. There are two options:
|
||||||
|
|
||||||
### Newline
|
### Newline
|
||||||
|
|
||||||
Start the block on a new line - defaults to `false`. For `pwsh` and `cmd` this will not print a newline that's defined
|
Start the block on a new line - defaults to `false`. For `bash`, `zsh`, `pwsh` and `cmd` this will not print a newline
|
||||||
on the first block when the prompt is on the first line (when using clear), or when the shell session starts (1st prompt).
|
that's defined on the first block when the prompt is on the first line (when using clear), or when the shell session
|
||||||
|
starts (1st prompt).
|
||||||
|
|
||||||
### Alignment
|
### Alignment
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue