diff options
author | nibon7 <nibon7@163.com> | 2022-12-02 19:40:36 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-02 12:40:36 +0100 |
commit | a7abc0f4508b5357e44bc1d0a8b0ed363201824c (patch) | |
tree | 2d26ee80ca24923baa31f7ab60cb236865a43ee6 | |
parent | 497039be07b977ec71fd411c28559c2b20a5b0e7 (diff) |
feat(nu): enable right prompt (#4490)
Closes #3982
-rw-r--r-- | docs/advanced-config/README.md | 4 | ||||
-rw-r--r-- | src/init/starship.nu | 29 |
2 files changed, 28 insertions, 5 deletions
diff --git a/docs/advanced-config/README.md b/docs/advanced-config/README.md index e468c44ea..f4adbb548 100644 --- a/docs/advanced-config/README.md +++ b/docs/advanced-config/README.md @@ -261,7 +261,9 @@ not explicitly used in either `format` or `right_format`. Note: The right prompt is a single line following the input location. To right align modules above the input line in a multi-line prompt, see the [`fill` module](/config/#fill). -`right_format` is currently supported for the following shells: elvish, fish, zsh, xonsh, cmd. +`right_format` is currently supported for the following shells: elvish, fish, zsh, xonsh, cmd, nushell. + +Note: Nushell 0.71.0 or later is required ### Example diff --git a/src/init/starship.nu b/src/init/starship.nu index 95a9b0b18..b57f40dbe 100644 --- a/src/init/starship.nu +++ b/src/init/starship.nu @@ -12,7 +12,28 @@ let-env PROMPT_COMMAND = { ^::STARSHIP:: prompt $"--cmd-duration=($env.CMD_DURATION_MS)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)" } -# Not well-suited for `starship prompt --right`. -# Built-in right prompt is equivalent to $fill$right_format in the first prompt line. -# Thus does not play well with default `add_newline = True`. -let-env PROMPT_COMMAND_RIGHT = {''} +# Whether we can show right prompt on the last line +let has_rprompt_last_line_support = (version).version >= 0.71.0 + +# Whether we have config items +let has_config_items = (not ($env | get -i config | is-empty)) + +if $has_rprompt_last_line_support { + let config = if $has_config_items { + $env.config | upsert render_right_prompt_on_last_line true + } else { + {render_right_prompt_on_last_line: true} + } + {config: $config} +} else { + { } +} | load-env + +let-env PROMPT_COMMAND_RIGHT = { + if $has_rprompt_last_line_support { + let width = (term size).columns + ^::STARSHIP:: prompt --right $"--cmd-duration=($env.CMD_DURATION_MS)" $"--status=($env.LAST_EXIT_CODE)" $"--terminal-width=($width)" + } else { + '' + } +} |