Skip to content

Commit 959847c

Browse files
authored
Document minimal config files (#1310)
* Document minimal config files * Nix `set-env` * Fix forked deploy * Explain forked deploy trick
1 parent bcf2a60 commit 959847c

File tree

3 files changed

+50
-29
lines changed

3 files changed

+50
-29
lines changed

.vuepress/config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@ const compareDate = (dateA, dateB) => {
3333
return dateB.getTime() - dateA.getTime();
3434
};
3535

36+
// default env from the deploy GitHub action
37+
// e.g. ciUser = nushell and ciRepo = nushell.github.io
38+
// both default to undefined if the env is undefined
39+
const [ciUser, ciRepo] = process.env.GITHUB_REPOSITORY?.split('/') ?? []
40+
3641
export default defineUserConfig({
42+
// set the base URL to ciRepo dir if it's a fork
43+
// keep the default root if not
44+
base: ciRepo && ciUser !== 'nushell' ? `/${ciRepo}/` : '/',
3745
locales: {
3846
'/': {
3947
lang: 'English',

CONTRIBUTING.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ If you want to contribute to nushell itself, see [nushell/nushell/CONTRIBUTING.m
44

55
This website is based on Vuepress.
66

7+
## Enabling a Preview URL From Your Fork
8+
9+
Just enable GitHub actions in your repo settings. That's all! It will start deploying the next time you push to `main`.
10+
711
## Running Vuepress locally
812

913
1. [Install Node.js](https://nodejs.org/en/download/), the minimum version required: v18.12.0

book/configuration.md

Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44

55
Nushell uses a configuration system that loads and runs two Nushell script files at launch time:
66

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`.
99

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`.
1111

1212
```nu
1313
> $nu.env-path
@@ -18,9 +18,16 @@ _(You can think of the Nushell config loading sequence as executing two [REPL](h
1818

1919
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).
2020

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:
2223

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
2431
an absolute path, Nushell will read config files from `$"($env.XDG_CONFIG_HOME)/nushell"`.
2532

2633
::: warning
@@ -37,12 +44,12 @@ C:\Users\username\.config\nushell
3744
```
3845

3946
::: warning
40-
`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.
4148
It should be the directory *above* the `nushell` directory. If you set it to `/Users/username/dotfiles/nushell`, Nushell will look for
4249
config files in `/Users/username/dotfiles/nushell/nushell` instead. In this case, you would want to set it to `/Users/username/dotfiles`.
4350
:::
4451

45-
### Configuring `$env.config`
52+
## Configuring `$env.config`
4653

4754
Nushell's main settings are kept in the `config` environment variable as a record. This record can be created using:
4855

@@ -51,8 +58,7 @@ $env.config = {
5158
...
5259
}
5360
```
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):
5662

5763
```nu
5864
$env.config = ($env.config | upsert <field name> <field value>)
@@ -82,21 +88,17 @@ These are some important variables to look at for Nushell-specific settings:
8288

8389
### Configurations with built-in commands
8490

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:
8892

89-
1. `$config.buffer_editor`
93+
1. `$env.config.buffer_editor`
9094
2. `$env.EDITOR`
9195
3. `$env.VISUAL`
9296

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-
9597
### Color Config section
9698

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

99-
## Remove Welcome Message
101+
### Remove Welcome Message
100102

101103
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:
102104

@@ -136,9 +138,9 @@ With this, you should be able to `chsh` and set Nu to be your login shell. After
136138

137139
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.
138140

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

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

143145
### macOS: Keeping `/usr/bin/open` as `open`
144146

@@ -147,7 +149,7 @@ As Nushell has its own [`open`](/commands/docs/open.md) command which has differ
147149
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:
148150

149151
```nu
150-
def nuopen [arg, --raw (-r)] { if $raw { open -r $arg } else { open $arg } }
152+
alias nu-open = open
151153
alias open = ^open
152154
```
153155

@@ -164,23 +166,31 @@ $env.PATH = ($env.PATH | split row (char esep) | append '/some/path')
164166

165167
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.
166168

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

169171
To add multiple paths only if not already listed, one can add to `env.nu`:
170172

171173
```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
180179
```
181180

182181
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.
183182

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+
184194
### Homebrew
185195

186196
[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:
213223
# Windows
214224
$env.Path = ($env.Path | split row (char esep) | prepend $"~/.pyenv/pyenv-win/bin/pyenv.ps1")
215225
```
216-

0 commit comments

Comments
 (0)