Skip to content

Commit 5671eb8

Browse files
authored
Add info on setting XDG_CONFIG_HOME (#1533)
* Add info on setting XDG_CONFIG_HOME * Update configuration.md * Minor formatting changes * Specify that /etc/environment is for PAM
1 parent f3226f5 commit 5671eb8

File tree

1 file changed

+20
-12
lines changed

1 file changed

+20
-12
lines changed

book/configuration.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -29,25 +29,33 @@ The default config files aren't required. If you prefer to start with an empty `
2929
:::
3030

3131
Control which directory Nushell reads config files from with the `XDG_CONFIG_HOME` environment variable. When you set it to
32-
an absolute path, Nushell will read config files from `$"($env.XDG_CONFIG_HOME)/nushell"`.
32+
an absolute path, Nushell will read config files from `$"($env.XDG_CONFIG_HOME)/nushell"`. For example, if you set it to
33+
`C:\Users\bob\.config`, Nushell will read config files from `C:\Users\bob\.config\nushell\`.
3334

3435
::: warning
35-
`XDG_CONFIG_HOME` must be set **before** starting Nushell. Do not set it in `env.nu`.
36+
`XDG_CONFIG_HOME` must be set **before** starting Nushell. Setting it in `env.nu` or `config.nu` won't change where Nushell
37+
looks for configuration files.
3638
:::
3739

38-
Here's an example for reading config files from `~/.config/nushell` rather than the default directory for Windows, which is `C:\Users\username\AppData\Roaming\nushell`.
40+
On Windows, you can persistently set the `XDG_CONFIG_HOME` environment variable through the Control Panel. To get there, just
41+
search for "environment variable" in the Start menu.
3942

40-
```nu
41-
> $env.XDG_CONFIG_HOME = "C:\Users\username\.config"
42-
> nu
43-
> $nu.default-config-dir
44-
C:\Users\username\.config\nushell
43+
On other platforms, if Nushell isn't your login shell, then you can set `XDG_CONFIG_HOME` before launching Nushell. For example, if you
44+
use MacOS and your login shell is Zsh, you could add the following to your `.zshrc`:
45+
46+
```zsh
47+
export XDG_CONFIG_HOME="/Users/bob/.config"
4548
```
4649

50+
If Nushell is your login shell, then ways to set `XDG_CONFIG_HOME` will depend on your OS.
51+
Some Linux distros will let you set environment variables in `/etc/profile` or `/etc/profile.d`.
52+
On modern Linux distros, you can also set it through PAM in `/etc/environment`.
53+
4754
::: warning
48-
[`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.
49-
It should be the directory _above_ the `nushell` directory. If you set it to `/Users/username/dotfiles/nushell`, Nushell will look for
50-
config files in `/Users/username/dotfiles/nushell/nushell` instead. In this case, you would want to set it to `/Users/username/dotfiles`.
55+
[`XDG_CONFIG_HOME`](https://xdgbasedirectoryspecification.com) is not a Nushell-specific environment variable and should not be set to the
56+
directory that contains Nushell config files. It should be the directory _above_ the `nushell` directory. If you set it to
57+
`/Users/username/dotfiles/nushell`, Nushell will look for config files in `/Users/username/dotfiles/nushell/nushell` instead.
58+
In this case, you would want to set it to `/Users/username/dotfiles`.
5159
:::
5260

5361
## Configuring `$env.config`
@@ -180,7 +188,7 @@ $env.PATH = (
180188
| append ($env.CARGO_HOME | path join bin)
181189
| append ($env.HOME | path join .local bin)
182190
| uniq # filter so the paths are unique
183-
)
191+
)
184192
```
185193

186194
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.

0 commit comments

Comments
 (0)