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/plugins.md
+77-4
Original file line number
Diff line number
Diff line change
@@ -10,6 +10,69 @@ When updating Nushell, please make sure to also update any plugins that you have
10
10
11
11
[[toc]]
12
12
13
+
## Overview
14
+
15
+
- In order to use a plugin, it needs to be:
16
+
17
+
- Installed
18
+
- Added
19
+
- Imported
20
+
21
+
There are two types of plugins:
22
+
23
+
- "Core plugins" are officially maintained and are usually installed with Nushell, in the same directory as the Nushell executable.
24
+
- Third-party plugins are also available from many sources.
25
+
26
+
The `$NU_LIB_DIRS` constant or `$env.NU_LIB_DIRS` environment variable can be used to set the search-path for plugins.
27
+
28
+
### Core Plugin Quickstart
29
+
30
+
To begin using the Polars plugin:
31
+
32
+
1. Most package managers will automatically install the core plugins with Nushell. A notable exception, however, is `cargo`. If you installed
33
+
Nushell using `cargo`, see [Installing Core Plugins](#core-plugins) below.
34
+
35
+
2. (Recommended) Set the plugin search path to include the directory where Nushell and its plugins are installed. Assuming the core plugins are installed
36
+
in the same directory as the Nushell binary, the following can be added to your startup config:
37
+
38
+
```nu
39
+
const NU_PLUGIN_DIRS = [
40
+
($nu.current-exe | path dirname)
41
+
...$NU_PLUGIN_DIRS
42
+
]
43
+
```
44
+
45
+
3. Add the plugin to the plugin registry. This only needs to be done one time. The name is the name of the plugin _file_, including its extension:
46
+
47
+
```nu
48
+
# On Unix/Linux platforms:
49
+
plugin add nu_plugin_polars
50
+
# Or on Windows
51
+
plugin add nu_plugin_polars.exe
52
+
53
+
plug list # Confirm it was added to the registry
54
+
```
55
+
56
+
Alternatively, if you did not add the binary directory to the plugin path in Step 2, you can still use an absolute path:
4. Import the plugin (to begin using it immediately) or restart Nushell. All plugins in the registry are automatically imported when Nushell starts:
63
+
64
+
```nu
65
+
# The name of the plugin, without the leading `nu_plugin` nor any extension
66
+
use polars
67
+
```
68
+
69
+
5. Confirm the plugin is working:
70
+
71
+
```nu
72
+
ls | polars into-df | describe
73
+
# => NuDataFrame
74
+
```
75
+
13
76
## Installing Plugins
14
77
15
78
### Core Plugins
@@ -29,7 +92,7 @@ Core plugins are typically distributed with the Nushell release and should alrea
29
92
::: tip Installing using Cargo
30
93
For example, when installing or upgrading Nushell directly from crates.io using `cargo install nu --locked`, the corresponding core plugins for that version may also be installed or updated using `cargo install nu_plugin_<plugin_name> --locked`.
31
94
32
-
To install all of the default plugins, from within Nushell run:
95
+
To install all of the default (non-developer) plugins, from within Nushell run:
33
96
34
97
```nu
35
98
[ nu_plugin_inc
@@ -96,15 +159,17 @@ When [`plugin add`](/commands/docs/plugin_add.md) is called, Nu:
96
159
- Communicates via the [plugin protocol](/contributor-book/plugin_protocol_reference.md) in order to ensure compatibility and to get a list of all of the commands it supports
97
160
- This plugin information is then saved to the plugin registry file (`$nu.plugin-path`), which acts as a cache
98
161
99
-
Once added to the registry, the next time `nu` is started, the plugin will be available in that session.
162
+
### Importing Plugins
163
+
164
+
Once added to the registry, the next time `nu` is started, the plugin will be imported and available in that session.
100
165
101
-
You can also immediately reload a plugin in the current session by calling `plugin use`. In this case, the name of the plugin (rather than the filename) is used without the `nu_plugin` prefix:
166
+
You can also immediately import (or reload) a plugin in the current session by calling `plugin use`. In this case, the name of the plugin (rather than the filename) is used without the `nu_plugin` prefix:
102
167
103
168
```nu
104
169
plugin use cool
105
170
```
106
171
107
-
It is not necessary to add `plugin use` statements to your config file. All previously added plugins are automatically loaded at startup.
172
+
It is not necessary to add `plugin use` statements to your config file. All previously registered plugins are automatically loaded at startup.
108
173
109
174
::: tip Note
110
175
`plugin use` is a parser keyword, so when evaluating a script, it will be evaluated first. This means that while you can execute `plugin add` and then `plugin use` at the REPL on separate lines, you can't do this in a single script. If you need to run `nu` with a specific plugin or set of plugins without preparing a cache file, you can pass the `--plugins` option to `nu` with a list of plugin executable files:
@@ -115,6 +180,14 @@ nu --plugins '[./my_plugins/nu_plugin_cool]'
115
180
116
181
:::
117
182
183
+
### Plugin Search Path
184
+
185
+
Nushell includes two `list` variables that can be used to set a search path for plugins. This only applies when registering plugins with `plugin add`, but it can be a nice shortcut
186
+
if you commonly add and remove plugins.
187
+
188
+
-`const NU_PLUGIN_DIRS`: A constant which takes effect immediately when set. However, as a constant, only certain commands may be used with it. It can be updated, for example, as seen in the [QuickStart above](#core-plugin-quickstart).
189
+
-`$env.NU_PLUGIN_DIRS`: An environment variable which is mutable and can accept any command that updates its list. However, changes to it will not take effect until the _next_ expression is parsed.
190
+
118
191
### Updating Plugins
119
192
120
193
When updating a plugin, it is important to run `plugin add` again just as above to load the new signatures from the plugin and allow Nu to rewrite them to the plugin file (`$nu.plugin-path`). You can then `plugin use` to get the updated signatures within the current session.
0 commit comments