Skip to content

Commit 6b7ac93

Browse files
132iklNotTheDr01ds
andcommitted
Address review notes
Co-authored-by: Douglas <32344964+NotTheDr01ds@users.noreply.github.com>
1 parent 0ea4770 commit 6b7ac93

File tree

2 files changed

+57
-48
lines changed

2 files changed

+57
-48
lines changed

book/modules.md

Lines changed: 54 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,12 @@ then
7878

7979
The result should be similar as in the previous section.
8080

81-
> **Note**
82-
> that the `use greetings.nu hello` call here first implicitly creates the `greetings` module,
83-
> then takes `hello` from it. You could also write it as `module greetings.nu`, `use greetings hello`.
84-
> Using `module` can be useful if you're not interested in any definitions from the module but want to,
85-
> e.g., re-export the module (`export module greetings.nu`).
81+
::: tip Note
82+
Note that the `use greetings.nu hello` call here first implicitly creates the `greetings` module,
83+
then takes `hello` from it. You could also write it as `module greetings.nu`, `use greetings hello`.
84+
Using `module` can be useful if you're not interested in any definitions from the module but want to,
85+
e.g., re-export the module (`export module greetings.nu`).
86+
:::
8687

8788
## Modules from Directories
8889

@@ -112,7 +113,7 @@ then
112113

113114
The name of the module follows the same rule as module created from a file: Stem of the directory name, i.e., the directory name, is used as the module name. Again, you could do this as a two-step action using `module` and `use` separately, as explained in the previous section.
114115

115-
::: tip
116+
::: tip Note
116117
You can define `main` command inside `mod.nu` to create a command named after the module directory.
117118
:::
118119

@@ -428,62 +429,68 @@ A common pattern in traditional shells is dumping and auto-sourcing files from a
428429
Here we'll create a simple completion module with a submodule dedicated to some Git completions:
429430

430431
1. Create the completion directory
432+
431433
`mkdir ($nu.default-config-dir | path join completions)`
434+
432435
2. Create an empty `mod.nu` for it
436+
433437
`touch ($nu.default-config-dir | path join completions mod.nu)`
438+
434439
3. Put the following snippet in `git.nu` under the `completions` directory
435440

436-
```nu
437-
export extern main [
438-
--version(-v)
439-
-C: string
440-
# ... etc.
441-
]
442-
443-
export extern add [
444-
--verbose(-v)
445-
--dry-run(-n)
446-
# ... etc.
447-
]
448-
449-
export extern checkout [
450-
branch: string@complete-git-branch
451-
]
452-
453-
def complete-git-branch [] {
454-
# ... code to list git branches
455-
}
456-
```
441+
```nu
442+
export extern main [
443+
--version(-v)
444+
-C: string
445+
# ... etc.
446+
]
447+
448+
export extern add [
449+
--verbose(-v)
450+
--dry-run(-n)
451+
# ... etc.
452+
]
453+
454+
export extern checkout [
455+
branch: string@complete-git-branch
456+
]
457+
458+
def complete-git-branch [] {
459+
# ... code to list git branches
460+
}
461+
```
457462

458463
4. Add `export module git.nu` to `mod.nu`
459464
5. Add the parent of the `completions` directory to your NU_LIB_DIRS inside `env.nu`
460465

461-
```nu
462-
$env.NU_LIB_DIRS = [
463-
...
464-
$nu.default-config-dir
465-
]
466-
```
466+
```nu
467+
$env.NU_LIB_DIRS = [
468+
...
469+
$nu.default-config-dir
470+
]
471+
```
472+
473+
6. Import the completions to Nushell in your `config.nu`:
467474

468-
6. import the completions to Nushell in your `config.nu`
469475
`use completions *`
470-
Now you've set up a directory where you can put your completion files and you should have some Git completions the next time you start Nushell
471476

472-
> **Note**
473-
> This will use the file name (in our example `git` from `git.nu`) as the module name. This means some completions might not work if the definition has the base command in its name.
474-
> For example, if you defined our known externals in our `git.nu` as `export extern 'git push' []`, etc. and followed the rest of the steps, you would get subcommands like `git git push`, etc.
475-
> You would need to call `use completions git *` to get the desired subcommands. For this reason, using `main` as outlined in the step above is the preferred way to define subcommands.
477+
Now you've set up a directory where you can put your completion files, and you should have some Git completions the next time you start Nushell.
478+
479+
::: tip Note
480+
This will use the file name (in our example `git` from `git.nu`) as the module name. This means some completions might not work if the definition has the base command in its name.
481+
For example, if you defined our known externals in our `git.nu` as `export extern 'git push' []`, etc. and followed the rest of the steps, you would get subcommands like `git git push`, etc.
482+
You would need to call `use completions git *` to get the desired subcommands. For this reason, using `main` as outlined in the step above is the preferred way to define subcommands.
483+
:::
476484

477485
### Setting environment + aliases (conda style)
478486

479487
`def --env` commands, `export-env` block and aliases can be used to dynamically manipulate "virtual environments" (a concept well known from Python).
480488

481-
We use it in our official virtualenv integration https://github.com/pypa/virtualenv/blob/main/src/virtualenv/activation/nushell/activate.nu
482-
483-
Another example could be our unofficial Conda module: https://github.com/nushell/nu_scripts/blob/f86a060c10f132407694e9ba0f536bfe3ee51efc/modules/virtual_environments/conda.nu
489+
We use it in our [official virtualenv integration](https://github.com/pypa/virtualenv/blob/main/src/virtualenv/activation/nushell/activate.nu). Another example is our [unofficial Conda module](https://github.com/nushell/nu_scripts/blob/main/modules/virtual_environments/conda.nu).
484490

485-
> **Warning**
486-
> Work In Progress
491+
::: warning
492+
Work in progress
493+
:::
487494

488495
## Hiding
489496

@@ -522,4 +529,6 @@ It can be one of the following:
522529

523530
- Hides all the module's exports, without the prefix
524531

525-
> **Note** > `hide` is not a supported keyword at the root of a module (unlike `def` etc.)
532+
:::tip Note
533+
`hide` is not a supported keyword at the root of a module (unlike `def` etc.)
534+
:::

book/scripts.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ Hello string +1
103103

104104
## Subcommands
105105

106-
A script's `main` command can have multiple [subcommands](custom_commands.html#subcommands) like `run`, `build`, etc. which allows executing a specific sub-function from the commandline.
107-
108-
For example:
106+
A script can have multiple [subcommands](custom_commands.html#subcommands), like `run` or `build` for example:
109107

110108
```nu
111109
# myscript.nu
@@ -122,6 +120,8 @@ def main [] {
122120
}
123121
```
124122

123+
You can then execute the script's subcommands when calling it:
124+
125125
```nu
126126
> nu myscript.nu
127127
hello from myscript!

0 commit comments

Comments
 (0)