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: book/configuration.md
+38-29Lines changed: 38 additions & 29 deletions
Original file line number
Diff line number
Diff line change
@@ -4,10 +4,10 @@
4
4
5
5
Nushell uses a configuration system that loads and runs two Nushell script files at launch time:
6
6
7
-
-`env.nu` is used to define environment variables. These typically get used in the second config file, config.nu.
8
-
-`config.nu` is used to add definitions, aliases, and more to the global namespace. It can use the environment variables defined in `env.nu`, which is why there's two separate files.
7
+
-`env.nu` is used to define environment variables or write files before `config.nu` starts. For example [`$env.NU_LIB_DIRS`](/book/modules.md#dumping-files-into-directory) controls where Nu finds imports. Third party scripts, like prompts or [mise](https://mise.jdx.dev/getting-started.html#nushell), must already be saved to disk before `config.nu` can read them.
8
+
-`config.nu` is used to add definitions, aliases, and more to the global namespace. It can also use the environment variables and constants defined in `env.nu`. If you can't decide which file to add stuff, prefer `config.nu`.
9
9
10
-
You can check where Nushell is reading these config files from by calling `$nu.env-path` and `$nu.config-path`.
10
+
Check where Nushell is reading these config files from by calling `$nu.env-path` and `$nu.config-path`.
11
11
12
12
```nu
13
13
> $nu.env-path
@@ -18,9 +18,16 @@ _(You can think of the Nushell config loading sequence as executing two [REPL](h
18
18
19
19
When you launch Nushell without these files set up, Nushell will prompt you to download the [`default env.nu`](https://github.com/nushell/nushell/blob/main/crates/nu-utils/src/sample_config/default_env.nu) and [`default config.nu`](https://github.com/nushell/nushell/blob/main/crates/nu-utils/src/sample_config/default_config.nu).
20
20
21
-
You can browse the default files for default values of environment variables and a list of all configurable settings.
21
+
::: tip
22
+
The default config files aren't required. If you prefer to start with an empty `env.nu` and `config.nu` then Nu applies identical defaults in internal Rust code. You can still browse the default files for default values of environment variables and a list of all configurable settings using the [`config`](#configurations-with-built-in-commands) commands:
22
23
23
-
You can control which directory Nushell reads config files from. If you set the `XDG_CONFIG_HOME` environment variable to
24
+
```nu
25
+
> config env --default | nu-highlight | lines
26
+
> config nu --default | nu-highlight | lines
27
+
```
28
+
:::
29
+
30
+
Control which directory Nushell reads config files from with the `XDG_CONFIG_HOME` environment variable. When you set it to
24
31
an absolute path, Nushell will read config files from `$"($env.XDG_CONFIG_HOME)/nushell"`.
`XDG_CONFIG_HOME` is not a Nushell-specific environment variable and should not be set to the directory that contains Nushell config files.
47
+
[`XDG_CONFIG_HOME`](https://xdgbasedirectoryspecification.com) is not a Nushell-specific environment variable and should not be set to the directory that contains Nushell config files.
41
48
It should be the directory *above* the `nushell` directory. If you set it to `/Users/username/dotfiles/nushell`, Nushell will look for
42
49
config files in `/Users/username/dotfiles/nushell/nushell` instead. In this case, you would want to set it to `/Users/username/dotfiles`.
43
50
:::
44
51
45
-
###Configuring `$env.config`
52
+
## Configuring `$env.config`
46
53
47
54
Nushell's main settings are kept in the `config` environment variable as a record. This record can be created using:
48
55
@@ -51,8 +58,7 @@ $env.config = {
51
58
...
52
59
}
53
60
```
54
-
55
-
You can also shadow `$env.config` and update it:
61
+
Note that setting any key overwrites its previous value. Likewise it's an error to reference any missing key. If `$env.config` already exists you can update or gracefully insert a [`cell-path`](/lang-guide/lang-guide.md#cellpath) at any depth using [`upsert`](/commands/docs/upsert.md):
@@ -82,21 +88,17 @@ These are some important variables to look at for Nushell-specific settings:
82
88
83
89
### Configurations with built-in commands
84
90
85
-
Starting with release v0.64 of Nushell, we have introduced two new commands([`config nu`](/commands/docs/config_nu.md) and [`config env`](/commands/docs/config_env.md)) which help you quickly edit nu configurations with your preferred text editor/IDE
86
-
87
-
Nushell follows underneath orders to locate the editor:
91
+
The ([`config nu`](/commands/docs/config_nu.md) and [`config env`](/commands/docs/config_env.md)) commands open their respective configurations for quick editing in your preferred text editor or IDE. Nu determines your editor from the following environment variables in order:
88
92
89
-
1.`$config.buffer_editor`
93
+
1.`$env.config.buffer_editor`
90
94
2.`$env.EDITOR`
91
95
3.`$env.VISUAL`
92
96
93
-
Note: Previous versions of Nushell were launching `notepad` on windows, otherwise `nano` when these variables weren't found. We removed defaulting to `notepad` on Windows since `notepad` is now distributed via the Windows Store and there will be a possibility of not having `notepad` at all.
94
-
95
97
### Color Config section
96
98
97
99
You can learn more about setting up colors and theming in the [associated chapter](coloring_and_theming.md).
98
100
99
-
## Remove Welcome Message
101
+
###Remove Welcome Message
100
102
101
103
To remove the welcome message, you need to edit your `config.nu` by typing `config nu` in your terminal, then you go to the global configuration `$env.config` and set `show_banner` option to false, like this:
102
104
@@ -136,9 +138,9 @@ With this, you should be able to `chsh` and set Nu to be your login shell. After
136
138
137
139
If Nushell is used as a login shell, you can use a specific configuration file which is only sourced in this case. Therefore a file with name `login.nu` has to be in the standard configuration directory.
138
140
139
-
The file `login.nu` is sourced after `env.nu` and `config.nu`, so that you can overwrite those configurations if you need.
141
+
The file `login.nu` is sourced after `env.nu` and `config.nu`, so that you can overwrite those configurations if you need. There is an environment variable `$nu.loginshell-path` containing the path to this file.
140
142
141
-
There is an environment variable `$nu.loginshell-path` containing the path to this file.
143
+
What about customizing iteractive shells, similar to `.zshrc`? By default `config.nu` is only loaded in interactive shells, not scripts.
142
144
143
145
### macOS: Keeping `/usr/bin/open` as `open`
144
146
@@ -147,7 +149,7 @@ As Nushell has its own [`open`](/commands/docs/open.md) command which has differ
147
149
One way to work around this is to define a custom command for Nushell's [`open`](/commands/docs/open.md) and create an alias for the system's [`open`](/commands/docs/open.md) in your `config.nu` file like this:
148
150
149
151
```nu
150
-
def nuopen [arg, --raw (-r)] { if $raw { open -r $arg } else { open $arg } }
This will append `/some/path` to the end of PATH; you can also use [`prepend`](/commands/docs/prepend.md) to add entries to the start of PATH.
166
168
167
-
Note the `split row (char esep)` step. We need to add it because in `env.nu`, the environment variables inherited from the host process are still strings. The conversion step of environment variables to Nushell values happens after reading the config files (see also the [Environment](environment.html#environment-variable-conversions) section). After that, for example in the Nushell REPL when `PATH`/`Path` is a list , you can use [`append`](/commands/docs/append.md)/[`prepend`](/commands/docs/prepend.md) directly.
169
+
Note the `split row (char esep)` step. We need to add it because in `env.nu`, the environment variables inherited from the host process are still strings. The conversion step of environment variables to Nushell values happens after reading the config files (see also the [Environment](environment.md#environment-variable-conversions) section). After that, for example in the Nushell REPL when `PATH`/`Path` is a list , you can use [`append`](/commands/docs/append.md)/[`prepend`](/commands/docs/prepend.md) directly.
168
170
169
171
To add multiple paths only if not already listed, one can add to `env.nu`:
170
172
171
173
```nu
172
-
$env.PATH = ($env.PATH |
173
-
split row (char esep) |
174
-
append /usr/local/bin |
175
-
append ($env.CARGO_HOME | path join "bin") |
176
-
append ($env.HOME | path join ".local" "bin")
177
-
)
178
-
# filter so the paths are unique
179
-
$env.PATH = ($env.PATH | uniq)
174
+
$env.PATH = $env.PATH | split row (char esep)
175
+
| append /usr/local/bin
176
+
| append ($env.CARGO_HOME | path join bin)
177
+
| append ($env.HOME | path join .local bin)
178
+
| uniq # filter so the paths are unique
180
179
```
181
180
182
181
This will add `/usr/local/bin`, the `bin` directory of CARGO_HOME, the `.local/bin` of HOME to PATH. It will also remove duplicates from PATH.
183
182
183
+
::: tip
184
+
There's a convenience command for updating your system path but you must first open the [`std`](/book/standard_library.md)[module](/book/cheat_sheet.md#modules) (in preview):
185
+
186
+
```nu
187
+
use std *
188
+
path add /usr/local/bin ($env.CARGO_HOME | path join bin) # etc.
189
+
```
190
+
191
+
You can optionally `--append` paths to be checked last like the ones below.
192
+
:::
193
+
184
194
### Homebrew
185
195
186
196
[Homebrew](https://brew.sh/) is a popular package manager that often requires PATH configuration. To add it to your Nushell PATH:
@@ -213,4 +223,3 @@ Then add the path of pyenv to your Nushell PATH:
0 commit comments