|
| 1 | +--- |
| 2 | +title: Upcoming Configuration Enhancements |
| 3 | +author: The Nu Authors |
| 4 | +author_site: https://twitter.com/nu_shell |
| 5 | +author_image: https://www.nushell.sh/blog/images/nu_logo.png |
| 6 | +excerpt: In the recent 0.100 release, we made some significant improvements to the way startup configuration is handled. We'll be building on that with some new features in the upcoming 0.101 release as well. Users who have been running nightly releases or building from source have been trialing these changes for about two weeks now. |
| 7 | +--- |
| 8 | + |
| 9 | +# Upcoming Configuration Enhancements |
| 10 | + |
| 11 | +In the recent 0.100 release, we made some significant improvements to the way startup configuration is handled. We'll be building on that with additional configuration changes in the upcoming 0.101 release as well. Users who have been running nightly releases or building from source have been trialing these changes for about two weeks now. |
| 12 | + |
| 13 | +Today, we're releasing two documentation items related to these changes: |
| 14 | + |
| 15 | +- A guide to upgrading your configuration to take advantage of the enhancements (below). This will also be linked from the 0.101 Release Notes when it becomes available. |
| 16 | + |
| 17 | +- A [preview of the new Configuration chapter](/book/configuration_preview.md) of the Book. This chapter has been rewritten to match the new functionality, as well as add some previously missing documentation on features like autoload dirs (and more). Once 0.101 releases, this will replace the previous configuration chapter. We welcome reviews of the updates, and any corrections or enhancements can be submitted to [the doc repository](https://github.com/nushell/nushell.github.io) if needed. |
| 18 | + |
| 19 | +--- |
| 20 | + |
| 21 | +**_Table of Contents_** |
| 22 | + |
| 23 | +[[toc]] |
| 24 | + |
| 25 | +--- |
| 26 | + |
| 27 | +## Upgrading Configuration to Nushell version 0.101.0 or later |
| 28 | + |
| 29 | +::: tip In a hurry? |
| 30 | +See [Setting Values in the New Config](#setting-values-in-the-new-config) below, then come back and read the rest if needed. |
| 31 | +::: |
| 32 | + |
| 33 | +### Overview |
| 34 | + |
| 35 | +In previous Nushell releases, the recommended practice was to include the **entire** `$env.config` record in `config.nu` and change values within it. Any `$env.config` keys that were not present in this record would use internal defaults, but these settings weren't introspectable in Nushell. |
| 36 | + |
| 37 | +With changes in releases 0.100 and 0.101, (most, but not all) missing values in `$env.config` are automatically populated in the record itself using the default, internal values. With this in place, it's no longer necessary to create a monolithic configuration record. |
| 38 | + |
| 39 | +If you have an existing `config.nu` with a complete `$env.config` record, you could continue to use it, but you should consider streamlining it based on these new features. This has the following advantages: |
| 40 | + |
| 41 | +- Startup will typically be slightly faster. |
| 42 | +- It's easier to see exactly which values are overridden, as those should be the only settings changed in `config.nu`. |
| 43 | +- Configurations are more easily modularized. |
| 44 | +- If a key name or default value changes in the future, it will only be a breaking change if it was a value that had been overridden. All other values will update seamlessly when you install new Nushell releases. |
| 45 | + |
| 46 | + ::: note |
| 47 | + This may be an advantage or disadvantage in some situations. For instance, at some point, we plan to switch the default history format to SQLite. When that change occurs in Nushell, it will automatically be changed for all users who hadn't overridden the value. That's a positive change for most users, as they'll automatically be switched to the more advanced format when they upgrade to that (as yet unknown) release, but that change may not be desirable for some users. |
| 48 | + |
| 49 | + Of course, these users can always simply override that value when and if the default changes. |
| 50 | + ::: |
| 51 | + |
| 52 | +Not _every_ default value is introspectable. The following Nushell internals are no longer set (by default) in `config.nu` and will not be automatically populated: |
| 53 | + |
| 54 | +- `keybindings` |
| 55 | +- `menus` |
| 56 | + |
| 57 | +However, the functionality behind them has always been handled internally by Nushell and Reedline. Only user-defined keybindings and menus should (as best-practice) be specified in the `$env.config`. |
| 58 | + |
| 59 | +### Finding Overridden Values |
| 60 | + |
| 61 | +To identify which values your current configuration has changed from the defaults, run the following in the current build (or 0.101 when available): |
| 62 | + |
| 63 | +```nu |
| 64 | +let defaults = nu -n -c "$env.config = {}; $env.config | reject color_config keybindings menus | to nuon" | from nuon | transpose key default |
| 65 | +let current = $env.config | reject color_config keybindings menus | transpose key current |
| 66 | +$current | merge $defaults | where $it.current != $it.default |
| 67 | +``` |
| 68 | + |
| 69 | +These are the values that you should migrate to your updated `config.nu`. |
| 70 | + |
| 71 | +::: note |
| 72 | +In the above example, `nu` (without a path) needs to point to a 0.101 or higher release in order for this to work. This should be the normal result, but users who are temporarily running from a compiled build (e.g. `./target/release/nu`) may need to adjust the command. |
| 73 | +::: |
| 74 | + |
| 75 | +Also examine: |
| 76 | + |
| 77 | +- Any theme/styling in `$env.config.color_config` and add those settings if desired. |
| 78 | +- Your personalized keybindings in `$env.config.keybindings`. Note that most (perhaps all) of the keybindings in the older default configuration files were simply examples that replicated built-in capabilities and did not change any Nushell functionality. |
| 79 | +- Any personalized menus in `$env.config.menus`. As with keybindings, you do not need to copy over examples. |
| 80 | + |
| 81 | +### Setting Values in the New Config |
| 82 | + |
| 83 | +Rather than defining a monolithic **`$env.config = { ... all values }`** as in the past, just create one entry for each setting you wish to **_override_**. For example: |
| 84 | + |
| 85 | +```nu |
| 86 | +$env.config.show_banner = false |
| 87 | +$env.config.buffer_editor = "code" |
| 88 | +
|
| 89 | +$env.config.history.file_format = "sqlite" |
| 90 | +$env.config.history.max_size: 1_000_000 |
| 91 | +$env.config.history.isolation = true |
| 92 | +
|
| 93 | +$env.config.keybindings ++= [{ |
| 94 | + name: "insert_last_token" |
| 95 | + modifier: "alt" |
| 96 | + keycode: "char_." |
| 97 | + event: [ |
| 98 | + { |
| 99 | + edit: "InsertString" |
| 100 | + value: "!$" |
| 101 | + }, |
| 102 | + { |
| 103 | + "send": "Enter" |
| 104 | + } |
| 105 | + ] |
| 106 | + mode: [ emacs, vi_normal, vi_insert ] |
| 107 | +}] |
| 108 | +``` |
| 109 | + |
| 110 | +::: note |
| 111 | +You could also set `$env.config.history` to a record, but it's recommended that you override all values if so. For example: |
| 112 | + |
| 113 | +```nu |
| 114 | +$env.config.history = { |
| 115 | + file_format: sqlite |
| 116 | + max_size: 1_000_000 |
| 117 | + sync_on_enter: true |
| 118 | + isolation: true |
| 119 | +} |
| 120 | +``` |
| 121 | + |
| 122 | +::: |
| 123 | + |
| 124 | +### Other Config Changes in 0.101 |
| 125 | + |
| 126 | +- The commented, sample `default_env.nu` and `default_config.nu` in older releases was useful for learning about configuration options. Since these (long) files are no longer copied to the filesystem, you can access an enhanced version of this documentation using: |
| 127 | + |
| 128 | + ```nu |
| 129 | + config env --sample | nu-highlight | less -R |
| 130 | + config nu --sample | nu-highlight | less -R |
| 131 | + ``` |
| 132 | + |
| 133 | +- Skeleton config files (`env.nu` and `config.nu`) are automatically created when the default config directory is created. Usually this will be the first time Nushell is started. The user will no longer be asked whether or not to create the files. |
| 134 | + |
| 135 | +- These files that are created have no configuration in them; just comments. This is because, "out-of-the-box", no values are overridden in the user config files. |
| 136 | + |
| 137 | +- An internal `default_env.nu` is loaded immediately before the user's `env.nu`. You can inspect its contents using `config env --default | nu-highlight | less -R`. |
| 138 | + |
| 139 | + This means that, as with `config.nu`, you can also use your `env.nu` to just override the default environment variables if desired. |
| 140 | + |
| 141 | +- Likewise, a `default_config.nu` is loaded immediately before the user's `config.nu`. View |
| 142 | + this file using `config nu --default | nu-highlight | less -R`. |
| 143 | + |
| 144 | +- `ENV_CONVERSIONS` are run several times so that the converted values may be used in `config.nu` and later files. It will now only convert `from_string` if the value was already a string. Otherwise, an already-converted-to-non-string value could cause issues with a `from_string` closure that wasn't expecting to be run multiple times. |
| 145 | + |
| 146 | +- The previous `$light_theme` and `$dark_theme` variables have been replaced by new standard library commands: |
| 147 | + |
| 148 | + ```nu |
| 149 | + use std/config * |
| 150 | + $env.config.color_config = (dark-theme) |
| 151 | + ``` |
0 commit comments