Skip to content

Commit

Permalink
feat(nu): enable right prompt
Browse files Browse the repository at this point in the history
  • Loading branch information
nibon7 committed Nov 28, 2022
1 parent c8ac877 commit e6fe1b3
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
4 changes: 3 additions & 1 deletion docs/advanced-config/README.md
Expand Up @@ -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

Expand Down
29 changes: 25 additions & 4 deletions src/init/starship.nu
Expand Up @@ -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 {
''
}
}

0 comments on commit e6fe1b3

Please sign in to comment.