Skip to content

Commit d6dcf80

Browse files
committed
Update config recommendations for 0.101
1 parent 767baa8 commit d6dcf80

File tree

2 files changed

+68
-58
lines changed

2 files changed

+68
-58
lines changed

blog/2024-12-04-configuration_preview.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,7 @@ $env.config.history = {
126126
- 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:
127127

128128
```nu
129-
config env --sample | nu-highlight | less -R
130-
config nu --sample | nu-highlight | less -R
129+
config nu --doc | nu-highlight | less -R
131130
```
132131

133132
- 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.
@@ -136,8 +135,6 @@ $env.config.history = {
136135

137136
- 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`.
138137

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-
141138
- Likewise, a `default_config.nu` is loaded immediately before the user's `config.nu`. View
142139
this file using `config nu --default | nu-highlight | less -R`.
143140

book/configuration_preview.md

Lines changed: 67 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ can get started with just a few simple steps:
2424
You can find a detailed list of available settings using:
2525

2626
```nu
27-
config nu --sample | nu-highlight | less -R
28-
config env --sample | nu-highlight | less -R
27+
config nu --doc | nu-highlight | less -R
2928
```
3029

3130
4. Save, exit the editor, and start a new Nushell session to load these settings.
@@ -40,8 +39,7 @@ That's it! More details are below when you need them ...
4039
To view a simplified version of this documentation from inside Nushell, run:
4140

4241
```nu
43-
config env --sample | nu-highlight | less -R
44-
config nu --sample | nu-highlight | less -R
42+
config env --doc | nu-highlight | less -R
4543
```
4644

4745
:::
@@ -50,7 +48,8 @@ config nu --sample | nu-highlight | less -R
5048

5149
Nushell uses multiple, optional configuration files. These files are loaded in the following order:
5250

53-
1. `env.nu` is typically used to define or override environment variables.
51+
1. The first file loaded is `env.nu`, which was historically used to override environment variables. However, the current "best-practice" recommendation is to set all environment variables (and other configuration) using `config.nu` and the autoload directories below.
52+
5453
2. `config.nu` is typically used to override default Nushell settings, define (or import) custom commands, or run any other startup tasks.
5554
3. Files in `$nu.vendor-autoload-dirs` are loaded. These files can be used for any purpose and are a convenient way to modularize a configuration.
5655
4. `login.nu` runs commands or handles configuration that should only take place when Nushell is running as a login shell.
@@ -85,7 +84,22 @@ $env.config.buffer_editor = 'code'
8584

8685
:::
8786

88-
## Common Configuration Tasks in `env.nu`:
87+
## Common Configuration Tasks in `config.nu`:
88+
89+
::: tip
90+
Some users will prefer a "monolithic" configuration file with most or all startup tasks in one place. `config.nu` can be used for this purpose.
91+
92+
Other users may prefer a "modular" configuration where each file handles a smaller, more focused set of tasks. Files in the autoload dirs can be used to create this experience.
93+
:::
94+
95+
`config.nu` is commonly used to:
96+
97+
- Set [environment variables](#set-environment-variables) for Nushell and other applications
98+
- Set Nushell settings in [`$env.config`](#nushell-settings-in-the-envconfig-record)
99+
- Load modules or source files so that their commands are readily available
100+
- Run any other applications or commands at startup
101+
102+
## Set Environment Variables
89103

90104
::: tip See Also
91105
The [Environment](./environment.md) Chapter covers additional information on how to set and access environment variables.
@@ -129,8 +143,7 @@ Nushell provides a number of prompt configuration options. By default, Nushell i
129143

130144
- A prompt which includes the current directory, abbreviated using `~` if it is (or is under)
131145
the home directory.
132-
- A prompt indicator which appears immediately to the right of the prompt. This defaults to `> ` when in normal editing mode, or a `: ` when in Vi-insert mode. Note
133-
extra space after the character to provide separation of the command from the prompt.
146+
- A prompt indicator which appears immediately to the right of the prompt. This defaults to `> ` when in normal editing mode, or a `: ` when in Vi-insert mode. Note extra space after the character to provide separation of the command from the prompt.
134147
- A right-prompt with the date and time
135148
- An indicator which is displayed when the current commandline extends over multiple lines - `::: ` by default
136149

@@ -178,6 +191,18 @@ The environment variables which control the transient prompt components are:
178191
- `$env.TRANSIENT_PROMPT_INDICATOR_VI_INSERT`: Vi-insert mode indicator
179192
- `$env.TRANSIENT_PROMPT_MULTILINE_INDICATOR`: The multi-line indicator
180193

194+
::: tip
195+
Nushell sets `TRANSIENT_PROMPT_COMMAND_RIGHT` and `TRANSIENT_PROMPT_MULTILINE_INDICATOR` to an empty string (`""`) so that each disappears after the previous command is entered. This simplifies copying and pasting from the terminal.
196+
197+
To disable this feature and always show those items, set:
198+
199+
```nu
200+
$env.TRANSIENT_PROMPT_COMMAND_RIGHT = null
201+
$env.TRANSIENT_PROMPT_MULTILINE_INDICATOR = null
202+
```
203+
204+
:::
205+
181206
### ENV_CONVERSIONS
182207

183208
Certain variables, such as those containing multiple paths, are often stored as a
@@ -200,29 +225,16 @@ variables are:
200225
```
201226

202227
::: tip
203-
The OS Path variable is automatically converted before `env.nu` loads. As a result, it can be treated as a list within `env.nu`. This conversion is handled via an initial, pre-defined `$env.ENV_CONVERSIONS` of:
204-
205-
```nu
206-
$env.ENV_CONVERSIONS = {
207-
"Path": {
208-
from_string: { |s| $s | split row (char esep) | path expand --no-symlink }
209-
to_string: { |v| $v | path expand --no-symlink | str join (char esep) }
210-
}
211-
}
212-
213-
```
214-
215-
Note that environment variables are not case-sensitive in Nushell, so the above will work
216-
for both Windows and Unix-like platforms.
228+
As mentioned above, the OS Path variable is automatically converted by Nushell. As a result, it can be treated as a list within `env.nu` without needing to be present in `ENV_CONVERSIONS`. Other colon-separated paths, like `XDG_DATA_DIRS`, are not automatically converted.
217229
:::
218230

219231
To add an additional conversion, [`merge`](/commands/docs/merge.md) it into the `$env.ENV_CONVERSIONS` record. For example, to add a conversion for the `XDG_DATA_DIRS` variable:
220232

221233
```nu
222234
$env.ENV_CONVERSIONS = $env.ENV_CONVERSIONS | merge {
223235
"XDG_DATA_DIRS": {
224-
from_string: { |s| $s | split row (char esep) | path expand --no-symlink }
225-
to_string: { |v| $v | path expand --no-symlink | str join (char esep) }
236+
from_string: {|s| $s | split row (char esep) | path expand --no-symlink }
237+
to_string: {|v| $v | path expand --no-symlink | str join (char esep) }
226238
}
227239
}
228240
```
@@ -231,31 +243,7 @@ $env.ENV_CONVERSIONS = $env.ENV_CONVERSIONS | merge {
231243

232244
As with many `ls`-like utilities, Nushell's directory listings make use of the `LS_COLORS` environment variable for defining styles/colors to apply to certain file types and patterns.
233245

234-
### Additional `$env.nu` Notes
235-
236-
While `env.nu` is typically used for environment variable configuration, this is purely by convention. Environment variables can be set in _any_
237-
of the available configuration files. Likewise, `env.nu` can be used for any purpose, if desired.
238-
239-
There are several configuration tasks where `env.nu` has advantages:
240-
241-
1. As mentioned above, `$env.ENV_CONVERSIONS` can be defined in `env.nu` to translate certain environment variables to (and from) Nushell structured data types. In order to treat these variables as structured-data in `config.nu`, then conversion needs to be defined in `env.nu`.
242-
243-
2. Modules or source files that are written or modified during `env.nu` can be imported or evaluated during `config.nu`. This is a fairly advanced, uncommon
244-
technique.
245-
246-
## Common Configuration Tasks in `config.nu`
247-
248-
The primary purpose of `config.nu` is to:
249-
250-
- Override default Nushell settings in the `$env.config` record
251-
- Define or import custom commands
252-
- Run other startup tasks
253-
254-
::: tip
255-
Some users will prefer a "monolithic" configuration file with most or all startup tasks in one place. `config.nu` can be used for this purpose.
256-
257-
Other users may prefer a "modular" configuration where each file handles a smaller, more focused set of tasks. Files in the autoload dirs can be used to create this experience.
258-
:::
246+
## Nushell Settings in the `$env.config` Record
259247

260248
### Changing Settings in the `$env.config` Record
261249

@@ -281,13 +269,12 @@ $env.config | table -e | bat -p
281269

282270
:::
283271

284-
An appendix documenting each setting will be available soon. In the meantime, abbreviated documentation on each setting can be
285-
viewed in Nushell using:
272+
An appendix documenting each setting will be available soon. In the meantime, abbreviated documentation on each setting can be viewed in Nushell using:
286273

287274
```nu
288-
config nu --sample | nu-highlight | bat
275+
config nu --doc | nu-highlight | bat
289276
# or
290-
config nu --sample | nu-highlight | less -R
277+
config nu --doc | nu-highlight | less -R
291278
```
292279

293280
To avoid overwriting existing settings, it's best to simply assign updated values to the desired configuration keys, rather than the entire `config` record. In other words:
@@ -446,7 +433,7 @@ rm $temp_home
446433

447434
### Using Constants
448435

449-
Some important commands, like `source` and `use`, that help define custom commands (and other definitions) are parse-time keywords. Along other things, this means means that all arguments must be known at parse-time.
436+
Some important commands, like `source` and `use`, that help define custom commands (and other definitions) are parse-time keywords. Among other things, this means means that all arguments must be known at parse-time.
450437

451438
In other words, **_variable arguments are not allowed for parser keywords_**.
452439

@@ -458,8 +445,16 @@ source ($nu.default-config-dir | path join "myfile.nu")
458445

459446
Because the constant value is known at parse-time, it can be used with parse-time keywords like `source` and `use`.
460447

448+
:::tip See Also
449+
See [Parse-time Constant Evaluation](./how_nushell_code_gets_run.md#parse-time-constant-evaluation) for more details on this parse.
450+
:::
451+
452+
#### `$nu` Constant
453+
461454
To see a list of the built-in Nushell constants, examine the record constant using `$nu` (including the dollar sign).
462455

456+
#### `NU_LIB_DIRS` Constant
457+
463458
Nushell can also make use of a `NU_LIB_DIRS` _constant_ which can act like the `$env.NU_LIB_DIRS` variable mentioned above. However, unlike `$env.NU_LIB_DIRS`, it can be defined _and_ used in `config.nu`. For example:
464459

465460
```nu
@@ -476,6 +471,24 @@ of paths will be searched. The constant `NU_LIB_DIRS` will be searched _first_ a
476471
precedence. If a file matching the name is found in one of those directories, the search will
477472
stop. Otherwise, it will continue into the `$env.NU_LIB_DIRS` search path.
478473

474+
#### `NU_PLUGIN_DIRS` Constant
475+
476+
`const NU_PLUGIN_DIRS` works in the same way for the plugin search path.
477+
478+
The following `NU_PLUGIN_DIRS` configuration will allow plugins to be loaded from;
479+
480+
- The directory where the `nu` executable is located. This is typically where plugins are located in release packages.
481+
- A directory in `$nu.data-dirs` named after the version of Nushell running (e.g. `0.100.0`).
482+
- A `plugins` directory in your `$nu.config-path`.
483+
484+
```nu
485+
const NU_PLUGIN_DIRS = [
486+
($nu.current-exe | path dirname)
487+
($nu.data-dir | path join 'plugins' | path join (version).version)
488+
($nu.config-path | path dirname | path join 'plugins')
489+
]
490+
```
491+
479492
### Colors, Theming, and Syntax Highlighting
480493

481494
You can learn more about setting up colors and theming in the [associated chapter](coloring_and_theming.md).

0 commit comments

Comments
 (0)