Repository navigation
feat(config)!: move the prompt into $env.config.prompt - #18734
Conversation
|
Hey, just a bot checking in! You edited files related to the configuration. |
|
When this lands we'll probably need to notify 3rd party's like on-my-posh and starship maybe. I'm not sure who exactly uses $env.PROMPT_COMMAND other than them. We'll also need to change our documentation. Just found couchbase shell uses it. |
|
I think actually that no one can really use it. Also regarding the issue with startship, i noticed that the Prompt indicator is actually not really playing into that and will be colored independently. |
|
Yeah okay they use it. I will take a look and maybe make a PR/issue for the change at the most important ones. |
|
But what we could actually just do it not warning and just keeping the fallback until they have merged. And only then start warning about it so individuals can change if they have defined a custom one through the env variable. |
|
oh-my-posh uses it too https://github.com/search?q=repo%3AJanDeDobbeleer%2Foh-my-posh+PROMPT_COMMAND&type=code - We should definitely make it a non-breaking change and maybe file issues on their repo. We could probably PR most of these ourselves since it's a pretty trivial change. |
|
Its non-breaking now already. |
Right. I think that's probably the best approach right now. Thanks! |
This one is for |
|
omp sets that too https://github.com/search?q=repo%3AJanDeDobbeleer%2Foh-my-posh+PROMPT_INDICATOR&type=code but I'm confused, why would we go through this change and not change all the PROMPT things to $env.config.prompt like prompt, right_prompt, transient, etc? It seems like it might be more confusing to have some things as env vars and some as config. I'd vote for all one or the other. |
|
Well that's a good question. |
ec1106e to
539ab19
Compare
|
@fdncred |
|
I don't like the idea of having all the prompt settings in one place and then changing it to two places. It's confusing. I think we either need to change all of them at once or leave them where they're at. |
The indicators moved in 4211353, which left the prompt configured in two places. fdncred's call on nushell#18734 was all or nothing, so this brings `PROMPT_COMMAND`, `PROMPT_COMMAND_RIGHT` and their transient twins across too. The variables still win when set, so starship, oh-my-posh and couchbase shell keep working untouched. Closures can live in config after all: `Hooks` already stores raw `Value`s that are closures, so `prompt.left` and `prompt.right` take a string used verbatim or a closure evaluated once per cycle, exactly what the variables took. The shipped default stays in `default_env.nu` since a closure needs a parsed block. Putting it in `default_config.nu` instead would load after the user's `env.nu` and clobber a prompt set there. No variable is seeded at startup any more. Seeding one would pin every session to it and leave the config key with no way to take effect, but it does mean code that reads `$env.PROMPT_INDICATOR` to discover the current prompt now finds nothing. `input --reedline` resolves the same way, so a user still on the variables does not get one indicator at the prompt and another inside `input`.
`Vi::default` and `Helix::default` both start in insert, thus the first glyph anyone saw on entering a modal mode was `: `, reserved for the state least like emacs, while the state they had landed in behaves exactly like it. Normal held `> `, so emacs and vi normal rendered alike. The two values are swapped rather than replaced, since `:` is the ex prompt and already means the keys are commands. Visual and select had no glyph at all and fell back to normal's. Still not a break, since the constants were unreachable before: the module is private and nothing re-exported them. They are public now and named for the state rather than the dialect, since vi and helix share every value and disagree only on what to call the third one. Downstreams with their own prompt see nothing change; nushell keeps its own defaults and matches by hand, a pass still open in nushell/nushell#18734 which currently carries the old pair.
The four prompt indicators were configured through bare environment
variables that `src/main.rs` seeded once at REPL startup and nothing
ever updated. They are now `$env.config.prompt.{indicator, vi_insert,
vi_normal, vi_visual, multiline}`, defaulting from
`PromptConfig::default()`.
The environment variables still take precedence when set, so existing
`env.nu` files render unchanged, but reaching for one emits a
deprecation warning pointing at the config key. It uses
`ReportMode::FirstUse`, so it shows once per session rather than
before every command.
`vi_visual` is new and config-only. Visual mode previously aliased the
vi normal indicator and fell back to "v " only when that was unset, so
it silently lost the distinction as soon as anyone configured vi
normal.
`ReedlinePrompt` carried its own `DEFAULT_VI_*` constants, so the vi mode indicators shown by `input --reedline` were hardcoded and disagreed with the REPL: vi normal rendered "〉" there and "> " in the REPL. They now come from `$env.config.prompt`, which removes the second source of truth and means configuring an indicator applies everywhere. The emacs slot is left alone. `input` repurposes it for the `(default: ...)` hint, and the caller already supplies their own prompt text, so `prompt_config.indicator` would append a second prompt.
`engine_state.get_config()` returns the global config, so a stack-scoped `$env.config.prompt` override was invisible to `input --reedline`. Every other config read in `nu-command` uses `stack.get_config(engine_state)`, which layers the stack config over the global one.
Sits next to `get_editor`, which resolves `$env.config.buffer_editor` against `$env.EDITOR` the same way. Nothing calls it yet; the prompt move in the following commit does, from both `nu-cli` and `nu-command`.
The indicators moved in 4211353, which left the prompt configured in two places. fdncred's call on nushell#18734 was all or nothing, so this brings `PROMPT_COMMAND`, `PROMPT_COMMAND_RIGHT` and their transient twins across too. The variables still win when set, so starship, oh-my-posh and couchbase shell keep working untouched. Closures can live in config after all: `Hooks` already stores raw `Value`s that are closures, so `prompt.left` and `prompt.right` take a string used verbatim or a closure evaluated once per cycle, exactly what the variables took. The shipped default stays in `default_env.nu` since a closure needs a parsed block. Putting it in `default_config.nu` instead would load after the user's `env.nu` and clobber a prompt set there. No variable is seeded at startup any more. Seeding one would pin every session to it and leave the config key with no way to take effect, but it does mean code that reads `$env.PROMPT_INDICATOR` to discover the current prompt now finds nothing. `input --reedline` resolves the same way, so a user still on the variables does not get one indicator at the prompt and another inside `input`.
The last prompt setting outside the section. Renaming it is breaking where the environment variables were not, since a config key has no older spelling that keeps winning. Aliasing the old name onto the new one was the first attempt and is worse than it looks: `$env.config` is rebuilt from `Config` after every update, so writes would keep working while reads of the old name failed. `deprecated_option` errors on assignment instead and names the replacement, which is a one-line fix for anyone who hits it.
The config bot asks for this whenever `doc_config.nu` drifts from the Rust defaults. Two behaviour notes have nowhere else to live: nothing is seeded at startup any more, so `hide-env TRANSIENT_PROMPT_COMMAND_RIGHT` no longer brings the live right prompt back and `null` is the replacement, and code that reads a `PROMPT_` variable to discover the current prompt has to read `$env.config.prompt` instead.
reedline swapped its insert and normal indicators and gave select a glyph of its own, so insert is now `> `, normal `: ` and visual `+ `. Ours still encoded the old assignment, thus the next reedline bump would have put `: ` back on vi insert and reintroduced exactly the confusion that change fixed. `nu-protocol` cannot name reedline's constants without depending on the line editor, so the values stay typed out and the existing `defaults_match_prompt_config` guard keeps the fallbacks in step. A drift test against the constants themselves belongs in the reedline bump, where `nu-cli` can see them. `input --reedline` read the vi indicators it had just lost and lumped helix select in with normal; it now reads the same config keys, and select takes the visual one, since that is the state whose motions grow a span.
32929cf to
db198c9
Compare
| # PROMPT_COMMAND: Defines the primary prompt. | ||
| # Note: PROMPT_INDICATOR is appended to this value. | ||
| # Default: A closure that displays the current directory with colors. | ||
| $env.PROMPT_COMMAND = {|| |
There was a problem hiding this comment.
seems like we should keep these as $env.config.prompt.left and .right. we moved these here from the env.nu file because we were deprecating the env.nu file. i wonder if we still need them in the default_env.nu file or not if we kept them here?
There was a problem hiding this comment.
You are right that removing them was unnecessary, but still doc_config.nu is never executed. It is only be used in config nu --doc.
We could move them into default_config.nu with some checks, but you can't really do a default value for a closure, so dropping is not possible. So no default_*.nu is not really a thing i think.
There was a problem hiding this comment.
I think it should probably stay in doc_config.nu as documentation and maybe in default_config.nu. We could call get_prompt_string() to set a default, couldn't we? But I was thinking default should be whatever reedline provides as a default.
|
The last thing I worry about on this PR is that it changes the emitting of OSC ansi escape sequences. I'm not saying it does but I'm wondering if it does. I'm not sure we have any tests that validate we're emitting them right or not but I know I worked a long time getting them to work and they emit at the same time the prompt is drawn, as i remember. |
|
We don't touch OSC, so in theory it should not be a problem, since we only change the origin for the prompt related definitions and OSC are handled somewhere else entirely. But I will still keep an eye out if there are enough tests to really claim that. |
A nested `nu` drew no indicator at all: its parent exported an empty `PROMPT_INDICATOR`, and with the startup seeding gone nothing overwrote it before it took precedence over `$env.config.prompt`. All twelve variables are hidden rather than the six the seeding used to cover, since each of them now overrides a config key. Only the REPL hides them, so a script still sees what it inherited.
Users still on the deprecated variables now see them at the prompt but not inside `input`, which is how `input` behaved before it read them. Keeping that consistency would have meant honoring whatever a parent shell exports, including the old vi assignment a released `nu` seeds.
The default left and right prompts exist only as closures in `default_env.nu`, since a closure needs a parsed block and thus cannot be a Rust default. That ties them to env.nu, which is on its way out. `default_prompt_left` and `default_prompt_right` reproduce those closures byte for byte. Nothing calls them yet: they become the default once nushell#18734 moves the prompts into `$env.config.prompt` and the closures can leave `default_env.nu`. They live in `nu-command` rather than `nu-cli` since everything they must agree with lives there: `is-admin`, the locale handling of `format date`, and `path relative-to`. That keeps the shared pieces crate-private and keeps `chrono::Locale` out of `nu-cli`, which only sees that type today through feature unification.
`env.nu` is on its way out, and the prompts were the last thing `default_env.nu` still set. They now live as Nu source in `nu-cli` and are evaluated ahead of every startup file, so nothing about the load order or the rendered prompt changes. Rendering them natively in Rust instead was tried and dropped: with a `null` default there is nothing to `view source` and nothing to wrap with `do`, and both are how people build on the default prompt today. Keeping them as source keeps them a real closure in `$env.config.prompt`.
|
i'm working on the ci security problem here #19026 |
The starship and oh-my-posh init scripts both set the old key, so reporting it as deprecated broke every one of their users. `omp.nu` assigns it directly, which aborted the init before `PROMPT_COMMAND` was set and skipped the rest of `config.nu`. starship puts it into `config:` inside `load-env`, which does not reparse the config, thus the error surfaced on some later, unrelated `$env.config` assignment. Writes now land on `prompt.render_right_on_last_line` without a warning, since a warning would fire on every startup for those users until the scripts are updated. Reads of the old name still fail, which neither script does.
c1a8ac2 hid all twelve deprecated variables at REPL start. Eight of those were overwritten at startup anyway, six seeded from `main.rs` and the two prompt commands set by `default_env.nu`, so hiding them changes nothing for an inherited value. The other four transient ones were never touched, and `TRANSIENT_PROMPT_COMMAND=... nu` from a parent shell or direnv stopped working.
The note in `nu-cmd-base` still said `input --reedline` resolves through the shared module, which dab429f undid.
…nfig The prompt resolver takes over the `ClosureEvalOnce::try_new` call that nushell#19159 gave `get_prompt_string`, so a prompt closure whose block is gone is still reported instead of panicking. `commandline set-prompt` builds its push as a `PromptContents` the way nushell#19236 does, with `vi_visual` added. The deprecation note in `doc_config.nu` names 0.118.0, the release this now lands in.
`Config::default()` cannot hold the two prompt closures, so `config default` said `null` for both and assigning its `prompt` back cleared the prompt. Startup records the closures it evaluates on the engine state, since `nu-command` cannot reach the Nu source in `nu-cli` and a command has no way to parse a block at run time.
$env.config.prompt
|
oh, i forgot about this one. we should land it when it's ready so we have time to work with it |
|
Yeah I will take a look at them once more to be sure they are clean as I planned them and will merge them soon. |
…8686) ## Description reedline prints a foreground color in front of the left and the right prompt, and `NushellPrompt` never overrode it. Thus every unstyled piece of a custom prompt, like a starship module with `style = "none"`, came out light green or purple instead of in the terminal's own foreground. `NushellPrompt` now answers `Color::Default` for a side that was supplied, and keeps reedline's colors for a side that falls back to the built-in prompt. The two sides are judged separately. The indicators keep their default colors. They are nushell's own rather than the prompt generator's, and styling one means putting the escapes into the indicator value. ## User-facing changes (Release notes) Fixed unstyled text in a custom prompt being tinted light green (left) or purple (right). It now uses the terminal's default foreground, as in other shells. A prompt that sets its own colors looks the same as before. ## Additional notes fixes #16384 Based on `main`, since the `PromptState` rewrite it needed is already there. It conflicts with #18734 in one hunk, both append tests to `crates/nu-cli/src/prompt.rs`, so whichever lands second needs that merge.
The indicator keys in `$env.config.prompt` were typed as strings since nushell#18734 moved them before `left` and `right`, when config was not yet thought to hold closures. Moving `left` and `right` later showed it can, but the indicators kept their type, thus `$env.PROMPT_INDICATOR` and friends took a closure while the keys replacing them did not. An indicator colored by the last exit code had no way across. A live indicator still rejects `null`, since every edit mode draws one. A closure that fails to render falls back to the built-in indicator. `input --reedline` evaluates the keys too, so a closure works there as well.
The indicator keys in `$env.config.prompt` were typed as strings since nushell#18734 moved them before `left` and `right`, when config was not yet thought to hold closures. Moving `left` and `right` later showed it can, but the indicators kept their type, thus `$env.PROMPT_INDICATOR` and friends took a closure while the keys replacing them did not. An indicator colored by the last exit code had no way across. A live indicator still rejects `null`, since every edit mode draws one. A closure that fails to render falls back to the built-in indicator. `input --reedline` evaluates the keys too, so a closure works there as well.
## Description #18734 moved the prompt into `$env.config.prompt`, but the indicator keys only took a string. `$env.PROMPT_INDICATOR` and the other indicator variables always took a closure too, thus migrating an indicator that changes with `$env.LAST_EXIT_CODE` to the new keys was not possible. This was never a decision. The indicators moved first, typed as `String`, before `left` and `right` joined the PR. When those followed it turned out config can hold closures after all (`Hooks` already does), but the indicator keys were never widened. The indicators now go through the same path as `left` and `right`: - **config**: the transient keys parse with `update_prompt_source`, the live keys with an `update_indicator` that differs only by rejecting `null`, since every edit mode draws an indicator. - **resolution**: every segment resolves through `resolve_prompt_source`, `vi_visual` (no variable) through `render` directly. - **removed**: `update_optional_string`, `resolve_indicator` and `resolve_transient_indicator`, which only existed to carry the narrower type. A closure that fails to render reports its error and falls back to the built-in indicator. `input --reedline` renders the keys the same way. **Scrutinize**: `crates/nu-cli/src/prompt_update.rs`, the evaluation order of the segments is kept since any of them may have side effects now. **Skim**: the test updates in `crates/nu-protocol/src/config/prompt.rs`, mostly `"x".into()` to `Value::test_string("x")`. Tests: `nu-protocol` `config::prompt` 15/15, `nu-cli` `prompt` 28/28 including a new `configured_indicators_accept_closures` that parses and renders real closures, `nu-command` `reedline_prompt` 1/1. Clippy with CI flags clean on the touched crates. ## User-facing changes (Release notes) `$env.config.prompt.indicator`, `vi_insert`, `vi_normal`, `vi_visual` and `multiline`, plus their `transient` counterparts, now accept a closure as well as a string, the same as `$env.PROMPT_INDICATOR` and friends always did. ```nu $env.config.prompt.indicator = {|| if $env.LAST_EXIT_CODE == 0 { "> " } else { $"(ansi red)> (ansi reset)" } } ``` ## Additional notes Follow-up to #18734. [](https://0rwx.com)
Description
The prompt was configured through twelve bare environment variables.
Six of them were seeded from Rust at REPL startup, two more by
default_env.nu, and nothing kept them in step with the config.All of it now lives in
$env.config.prompt, together withrender_right_prompt_on_last_line.The old variables still take precedence when a session sets them, and nothing warns yet.
Thus every init script that writes them (starship, oh-my-posh, Dorothy, Couchbase Shell) keeps working unchanged.
The warning can follow once those have moved.
The default left and right prompts are still Nu closures.
A closure needs a parsed block, so they cannot sit in
Config::default().nu-clievaluates them into$env.config.promptbefore any config file runs, which keepsview source $env.config.prompt.leftworking and lets a config wrap the default.The indicators cannot move into the prompt closure, since reedline hands
render_prompt_indicatorthe currentPromptEditMode, which the closure cannot see.input --reedlinereads the same config now and drops its own hardcoded indicators.User-facing changes (Release notes)
The prompt is configured through
$env.config.promptleft$env.PROMPT_COMMANDright$env.PROMPT_COMMAND_RIGHTindicator"> "$env.PROMPT_INDICATORvi_insert"> "$env.PROMPT_INDICATOR_VI_INSERTvi_normal": "$env.PROMPT_INDICATOR_VI_NORMALvi_visual"+ "multiline"::: "$env.PROMPT_MULTILINE_INDICATORrender_right_on_last_linefalse$env.config.render_right_prompt_on_last_linetransient.leftnull$env.TRANSIENT_PROMPT_COMMANDtransient.right""$env.TRANSIENT_PROMPT_COMMAND_RIGHTtransient.indicatornull$env.TRANSIENT_PROMPT_INDICATORtransient.vi_insertnull$env.TRANSIENT_PROMPT_INDICATOR_VI_INSERTtransient.vi_normalnull$env.TRANSIENT_PROMPT_INDICATOR_VI_NORMALtransient.vi_visualnulltransient.multiline""$env.TRANSIENT_PROMPT_MULTILINE_INDICATORA transient key set to
nullkeeps whatever the live prompt showed.The twelve environment variables are deprecated.
They still win over the config when you set them, so a config or init script that assigns them keeps working.
Breaking changes
$env.PROMPT_COMMAND,$env.PROMPT_INDICATORand the rest now exist only if you set them yourself.Code that reads one to find the current prompt, like
let old = $env.PROMPT_COMMAND, has to read$env.config.prompt.leftinstead.hide-env TRANSIENT_PROMPT_COMMAND_RIGHT, the old way to keep the right prompt in the transient prompt, now errors as well.Set
$env.config.prompt.transient.right = nullinstead.$env.config.render_right_prompt_on_last_linecan no longer be read.Assigning the old name still sets
prompt.render_right_on_last_line.Insert mode shows
"> "(was": "), normal mode": "(was"> ")."+ ".It no longer follows
$env.PROMPT_INDICATOR_VI_NORMAL.Helix select mode uses it too.
input --reedlinefollows$env.config.prompt, so its vi normal indicator changed from"〉"to": "and its vi insert indicator from": "to"> ".commandline set-promptgained--vi-visual.config defaultreports the default prompt closures, so$env.config.prompt = (config default).promptrestores the default prompt.Fixed the reverse-search indicator running into the matched entry:
(reverse-search: ls)ls -lais now(reverse-search: ls) ls -la.Additional notes
Checked against the nushell integration of every project in the README's "Officially Supported By" list.
Only virtualenv reads one of the variables:
activate.nuwraps$env.PROMPT_COMMAND, and with nothing seeded the venv prompt loses the default prompt behind its prefix.uv ships a copy of the same script.
Both need a fallback to
$env.config.prompt.left, and venvs created before that fix keep the old script.The starship and oh-my-posh init scripts were run against this branch and against
mainon a pty.They render the same in emacs mode, in vi mode the only difference is the new default indicator.
OSC 133/633 emission is untouched, the sequences of a session on this branch and on
mainare identical.