mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2024-12-28 12:29:40 -08:00
fix(bash): remove rprompt support
BREAKING CHANGE: rprompt is no longer supported for bash due to too many side effects that have no solution in sight.
This commit is contained in:
parent
083c204694
commit
cdfd249b28
|
@ -1,37 +1,25 @@
|
|||
package prompt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/config"
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/log"
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/shell"
|
||||
"github.com/jandedobbeleer/oh-my-posh/src/terminal"
|
||||
)
|
||||
|
||||
func (e *Engine) RPrompt() string {
|
||||
var rprompt *config.Block
|
||||
var lineCount int
|
||||
|
||||
for _, block := range e.Config.Blocks {
|
||||
if block.Type == config.RPrompt {
|
||||
rprompt = block
|
||||
if block.Type != config.RPrompt {
|
||||
continue
|
||||
}
|
||||
|
||||
if block.Newline || block.Type == config.LineBreak {
|
||||
lineCount++
|
||||
}
|
||||
rprompt = block
|
||||
break
|
||||
}
|
||||
|
||||
if rprompt == nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
if e.Env.Shell() == shell.BASH {
|
||||
terminal.Init(shell.GENERIC)
|
||||
}
|
||||
|
||||
rprompt.Init(e.Env)
|
||||
|
||||
if !rprompt.Enabled() {
|
||||
|
@ -41,28 +29,5 @@ func (e *Engine) RPrompt() string {
|
|||
text, length := e.renderBlockSegments(rprompt)
|
||||
e.rpromptLength = length
|
||||
|
||||
if e.Env.Shell() != shell.BASH {
|
||||
return text
|
||||
}
|
||||
|
||||
width, err := e.Env.TerminalWidth()
|
||||
if err != nil {
|
||||
log.Error(err)
|
||||
return ""
|
||||
}
|
||||
|
||||
padding := width - e.rpromptLength
|
||||
if padding < 0 {
|
||||
padding = 0
|
||||
}
|
||||
|
||||
text = fmt.Sprintf("%s%s\r", strings.Repeat(" ", padding), text)
|
||||
|
||||
// bash prints this on the same line as the prompt so we need to move the cursor down
|
||||
// in case the prompt spans multiple lines
|
||||
if lineCount > 0 {
|
||||
return terminal.SaveCursorPosition() + fmt.Sprintf("\x1b[%bB", lineCount) + text + terminal.RestoreCursorPosition()
|
||||
}
|
||||
|
||||
return text
|
||||
}
|
||||
|
|
|
@ -76,16 +76,12 @@ function _omp_hook() {
|
|||
_omp_set_cursor_position
|
||||
|
||||
PS1="$(::OMP:: print primary --config="$POSH_THEME" --shell=bash --shell-version="$BASH_VERSION" --status="$_omp_status_cache" --pipestatus="${_omp_pipestatus_cache[*]}" --execution-time="$_omp_elapsed" --stack-count="$_omp_stack_count" --no-status="$_omp_no_exit_code" --terminal-width="${COLUMNS-0}" | tr -d '\0')"
|
||||
}
|
||||
|
||||
# rprompt
|
||||
function _omp_rprompt() {
|
||||
::OMP:: print right --config="$POSH_THEME" --shell=bash --shell-version="$BASH_VERSION" --status="$_omp_status_cache" --pipestatus="${_omp_pipestatus_cache[*]}" --execution-time="$_omp_elapsed" --stack-count="$_omp_stack_count" --no-status="$_omp_no_exit_code" --terminal-width="${COLUMNS-0}" | tr -d '\0'
|
||||
return $_omp_status_cache
|
||||
}
|
||||
|
||||
if [[ "$TERM" != "linux" ]] && [[ -x "$(command -v ::OMP::)" ]] && ! [[ "$PROMPT_COMMAND" =~ "_omp_hook" ]]; then
|
||||
PROMPT_COMMAND="_omp_hook; _omp_rprompt; $PROMPT_COMMAND"
|
||||
PROMPT_COMMAND="_omp_hook; $PROMPT_COMMAND"
|
||||
fi
|
||||
|
||||
if [[ "::UPGRADE::" == "true" ]]; then
|
||||
|
|
|
@ -41,13 +41,7 @@ Tells the engine what to do with the block. There are two options:
|
|||
|
||||
- `prompt` renders one or more segments
|
||||
- `rprompt` renders one or more segments aligned to the right of the cursor. Only one `rprompt` block is permitted.
|
||||
Supported on zsh, bash, PowerShell, cmd, nu and fish.
|
||||
|
||||
:::warning bash
|
||||
`rprompt` is not natively supported in bash and comes with one side effect. When you have a multiline prompt,
|
||||
the `rprompt` will not display when your new prompt is drawn at the bottom of the terminal. This is a limitation
|
||||
of bash and not Oh My Posh.
|
||||
:::
|
||||
Supported on zsh, PowerShell, cmd, nu and fish.
|
||||
|
||||
### Newline
|
||||
|
||||
|
|
Loading…
Reference in a new issue