You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: blog/2024-12-04-configuration_preview.md
+1-4Lines changed: 1 addition & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -126,8 +126,7 @@ $env.config.history = {
126
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
127
128
128
```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
131
130
```
132
131
133
132
- 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 = {
136
135
137
136
- 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
137
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
138
- Likewise, a `default_config.nu` is loaded immediately before the user's `config.nu`. View
142
139
this file using `config nu --default | nu-highlight | less -R`.
Copy file name to clipboardExpand all lines: book/configuration_preview.md
+67-54Lines changed: 67 additions & 54 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -24,8 +24,7 @@ can get started with just a few simple steps:
24
24
You can find a detailed list of available settings using:
25
25
26
26
```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
29
28
```
30
29
31
30
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 ...
40
39
To view a simplified version of this documentation from inside Nushell, run:
41
40
42
41
```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
45
43
```
46
44
47
45
:::
@@ -50,7 +48,8 @@ config nu --sample | nu-highlight | less -R
50
48
51
49
Nushell uses multiple, optional configuration files. These files are loaded in the following order:
52
50
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
+
54
53
2.`config.nu` is typically used to override default Nushell settings, define (or import) custom commands, or run any other startup tasks.
55
54
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.
56
55
4.`login.nu` runs commands or handles configuration that should only take place when Nushell is running as a login shell.
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
89
103
90
104
::: tip See Also
91
105
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
129
143
130
144
- A prompt which includes the current directory, abbreviated using `~` if it is (or is under)
131
145
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.
134
147
- A right-prompt with the date and time
135
148
- An indicator which is displayed when the current commandline extends over multiple lines - `::: ` by default
136
149
@@ -178,6 +191,18 @@ The environment variables which control the transient prompt components are:
-`$env.TRANSIENT_PROMPT_MULTILINE_INDICATOR`: The multi-line indicator
180
193
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
+
181
206
### ENV_CONVERSIONS
182
207
183
208
Certain variables, such as those containing multiple paths, are often stored as a
@@ -200,29 +225,16 @@ variables are:
200
225
```
201
226
202
227
::: 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:
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.
217
229
:::
218
230
219
231
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:
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.
233
245
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.
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:
286
273
287
274
```nu
288
-
config nu --sample | nu-highlight | bat
275
+
config nu --doc | nu-highlight | bat
289
276
# or
290
-
config nu --sample | nu-highlight | less -R
277
+
config nu --doc | nu-highlight | less -R
291
278
```
292
279
293
280
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
446
433
447
434
### Using Constants
448
435
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.
450
437
451
438
In other words, **_variable arguments are not allowed for parser keywords_**.
Because the constant value is known at parse-time, it can be used with parse-time keywords like `source` and `use`.
460
447
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
+
461
454
To see a list of the built-in Nushell constants, examine the record constant using `$nu` (including the dollar sign).
462
455
456
+
#### `NU_LIB_DIRS` Constant
457
+
463
458
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:
464
459
465
460
```nu
@@ -476,6 +471,24 @@ of paths will be searched. The constant `NU_LIB_DIRS` will be searched _first_ a
476
471
precedence. If a file matching the name is found in one of those directories, the search will
477
472
stop. Otherwise, it will continue into the `$env.NU_LIB_DIRS` search path.
478
473
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`.
0 commit comments