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/hooks.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,7 +1,7 @@
1
1
# Hooks
2
2
3
3
Hooks allow you to run a code snippet at some predefined situations.
4
-
They are only available in the interactive mode ([REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop)), they do not work if you run a Nushell with a script (`nu script.nu`) or commands (`nu -c "print foo"`) arguments.
4
+
They are only available in the interactive mode ([REPL](https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop)), they do not work if you run Nushell with a script (`nu script.nu`) or command (`nu -c "print foo"`) argument.
5
5
6
6
Currently, we support these types of hooks:
7
7
@@ -41,7 +41,7 @@ $env.config = {
41
41
}
42
42
```
43
43
44
-
Try putting the above to your config, running Nushell and moving around your filesystem.
44
+
Try putting the above into your config, running Nushell and moving around your filesystem.
45
45
When you change a directory, the `PWD` environment variable changes and the change triggers the hook with the previous and the current values stored in `before` and `after` variables, respectively.
46
46
47
47
Instead of defining just a single hook per trigger, it is possible to define a **list of hooks** which will run in sequence:
This won't work because the environment will be active only within the [`if`](/commands/docs/if.md) block.
120
120
In this case, you could easily rewrite it as `load-env (if $after == ... { ... } else { {} })` but this pattern is fairly common and later we'll see that not all cases can be rewritten like this.
121
121
122
-
To deal with the above problem, we introduce another way to define a hook --**a record**:
122
+
To deal with the above problem, we introduce another way to define a hook - **a record**:
0 commit comments