mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-21 02:55:37 -08:00
fix(nu): use native right prompt command
resolves #4237 this also avoids renderibng the right prompt twice when the shell script uses the `oh-my-posh print right` command
This commit is contained in:
parent
81fd4fa5e6
commit
b887d13ccd
|
@ -42,6 +42,17 @@ func (e *Engine) Primary() string {
|
|||
cancelNewline = !didRender
|
||||
}
|
||||
|
||||
// only render rprompt for shells where we need it from the primary prompt
|
||||
renderRPrompt := true
|
||||
switch e.Env.Shell() {
|
||||
case shell.ELVISH, shell.FISH, shell.NU, shell.XONSH, shell.CMD:
|
||||
renderRPrompt = false
|
||||
}
|
||||
|
||||
if block.Type == RPrompt && !renderRPrompt {
|
||||
continue
|
||||
}
|
||||
|
||||
if e.renderBlock(block, cancelNewline) {
|
||||
didRender = true
|
||||
}
|
||||
|
@ -79,7 +90,7 @@ func (e *Engine) Primary() string {
|
|||
prompt := fmt.Sprintf("PS1=\"%s\"", strings.ReplaceAll(e.string(), `"`, `\"`))
|
||||
prompt += fmt.Sprintf("\nRPROMPT=\"%s\"", e.rprompt)
|
||||
return prompt
|
||||
case shell.PWSH, shell.PWSH5, shell.GENERIC, shell.NU:
|
||||
case shell.PWSH, shell.PWSH5, shell.GENERIC:
|
||||
e.writeRPrompt()
|
||||
case shell.BASH:
|
||||
space, OK := e.canWriteRightBlock(true)
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
export-env {
|
||||
$env.config = ($env.config | upsert render_right_prompt_on_last_line true)
|
||||
|
||||
$env.POWERLINE_COMMAND = 'oh-my-posh'
|
||||
$env.POSH_THEME = ::CONFIG::
|
||||
$env.PROMPT_INDICATOR = ""
|
||||
$env.POSH_PID = (random uuid)
|
||||
# By default displays the right prompt on the first line
|
||||
# making it annoying when you have a multiline prompt
|
||||
# making the behavior different compared to other shells
|
||||
$env.PROMPT_COMMAND_RIGHT = ''
|
||||
$env.POSH_SHELL_VERSION = (version | get version)
|
||||
|
||||
# PROMPTS
|
||||
|
@ -25,6 +22,15 @@ export-env {
|
|||
let width = ((term size).columns | into string)
|
||||
^::OMP:: print primary $"--config=($env.POSH_THEME)" --shell=nu $"--shell-version=($env.POSH_SHELL_VERSION)" $"--execution-time=($cmd_duration)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)" $"--cleared=($clear)"
|
||||
}
|
||||
|
||||
$env.PROMPT_COMMAND_RIGHT = { ||
|
||||
# We have to do this because the initial value of `$env.CMD_DURATION_MS` is always `0823`,
|
||||
# which is an official setting.
|
||||
# See https://github.com/nushell/nushell/discussions/6402#discussioncomment-3466687.
|
||||
let cmd_duration = if $env.CMD_DURATION_MS == "0823" { 0 } else { $env.CMD_DURATION_MS }
|
||||
|
||||
let width = ((term size).columns | into string)
|
||||
^::OMP:: print right $"--config=($env.POSH_THEME)" --shell=nu $"--shell-version=($env.POSH_SHELL_VERSION)" $"--execution-time=($cmd_duration)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)"
|
||||
}
|
||||
|
||||
if "::UPGRADE::" == "true" {
|
||||
|
|
|
@ -158,7 +158,7 @@ Once altered, reload your config for the changes to take effect.
|
|||
<TabItem value="nu">
|
||||
|
||||
:::caution
|
||||
Oh My Posh requires Nushell v0.78.0 or higher.
|
||||
Oh My Posh requires Nushell v0.84.0 or higher.
|
||||
:::
|
||||
|
||||
Adjust the Oh My Posh init line in the Nushell env file (`$nu.env-path`) by adding the `--config` flag
|
||||
|
|
|
@ -104,7 +104,7 @@ exec fish
|
|||
<TabItem value="nu">
|
||||
|
||||
:::caution
|
||||
Oh My Posh requires Nushell v0.78.0 or higher.
|
||||
Oh My Posh requires Nushell v0.84.0 or higher.
|
||||
:::
|
||||
|
||||
Add the following line to the Nushell env file (`$nu.env-path`):
|
||||
|
|
Loading…
Reference in a new issue