Skip to content

Make $env.config access produce a record describing the full state of EngineState.config #7059

@webbedspace

Description

@webbedspace

Related problem

Breakoff of discussion here. $env.config access is currently a brittle way of querying the system configuration state (e.g. to check the state of always_trash for UX purposes), because you can put invalid values on $env.config like $env.config.rm_always_trash = 'foobarbaz' and have it actually stick on the record (even though doing so does not update EngineState for obvious reasons), and moreover you can write things like let-env config = "foobarbaz" that just blow the whole record away outright.

Describe the solution you'd like

My idea is that each $env.config access (that is to say, anything that reads from that value) causes Nushell to instead create and return a new record which always and only has values corresponding to those on the EngineState.config struct.

The struct looks like this:

pub struct Config {
    pub external_completer: Option<usize>,
    pub filesize_metric: bool,
    pub table_mode: String,
    pub use_ls_colors: bool,
    pub color_config: HashMap<String, Value>,
    pub use_grid_icons: bool,
    pub footer_mode: FooterMode,
    pub float_precision: i64,
    pub max_external_completion_results: i64,
    pub filesize_format: String,
    pub use_ansi_coloring: bool,
    pub quick_completions: bool,
    pub partial_completions: bool,
    pub completion_algorithm: String,
    pub edit_mode: String,
    pub max_history_size: i64,
    pub sync_history_on_enter: bool,
    pub history_file_format: HistoryFileFormat,
    pub log_level: String,
    pub keybindings: Vec<ParsedKeybinding>,
    pub menus: Vec<ParsedMenu>,
    pub hooks: Hooks,
    pub rm_always_trash: bool,
    pub shell_integration: bool,
    pub buffer_editor: String,
    pub table_index_mode: TableIndexMode,
    pub cd_with_abbreviations: bool,
    pub case_sensitive_completions: bool,
    pub enable_external_completion: bool,
    pub trim_strategy: TrimStrategy,
    pub show_banner: bool,
    pub show_clickable_links_in_ls: bool,
    pub render_right_prompt_on_last_line: bool,
}

$env.config access would thus produce a record holding external_completer, filesize_metric, table_mode, use_ls_colors, color_config, use_grid_icons, footer_mode, float_precision, max_external_completion_results, filesize_format, use_ansi_coloring, quick_completions, partial_completions, completion_algorithm, edit_mode, max_history_size, sync_history_on_enter, history_file_format, log_level, keybindings, menus, hooks, rm_always_trash, shell_integration, buffer_editor, table_index_mode, cd_with_abbreviations, case_sensitive_completions, enable_external_completion, trim_strategy, show_banner, show_clickable_links_in_ls, render_right_prompt_on_last_line keys.

Now, HistoryFileFormat, FooterMode, TrimStrategy and TableIndexMode can be translated back to Nuon values relatively easily. ParsedKeybinding and ParsedMenu might be a bit trickier (haven't examined them just yet).

Describe alternatives you've considered

No response

Additional context and details

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions