and '/path/to/target/dir' in ($before | default "")
and 'test-env' in (overlay list))
}
code: "overlay hide test-env --keep-env [ PWD ]"
}
]
})
```
### Filtering or Diverting Command Output
You can use the `display_output` hook to redirect the output of commands.
You should define a block that works on all value types.
The output of external commands is not filtered through `display_output`.
This hook can display the output in a separate window,
perhaps as rich HTML text. Here is the basic idea of how to do that:
```nu
$env.config = ($env.config | upsert hooks {
display_output: { to html --partial --no-color | save --raw /tmp/nu-output.html }
})
```
You can view the result by opening `file:///tmp/nu-output.html` in
a web browser.
Of course this isn't very convenient unless you use
a browser that automatically reloads when the file changes.
Instead of the [`save`](/commands/docs/save.md) command, you would normally customize this
to send the HTML output to a desired window.
### Changing how Output is Displayed
You can change to default behavior of how output is displayed by using the `display_output` hook.
Here is an example that changes the default display behavior to show a table 1 layer deep if the terminal is wide enough, or collapse otherwise:
```nu
$env.config = ($env.config | upsert hooks {
display_output: {if (term size).columns >= 100 { table -ed 1 } else { table }}
})
```
### `command_not_found` Hook in _Arch Linux_
The following hook uses the `pkgfile` command, to find which packages commands belong to in _Arch Linux_.
```nu
$env.config = {
...other config...
hooks: {
...other hooks...
command_not_found: {
|cmd_name| (
try {
let pkgs = (pkgfile --binaries --verbose $cmd_name)
if ($pkgs | is-empty) {
return null
}
(
$"(ansi $env.config.color_config.shape_external)($cmd_name)(ansi reset) " +
$"may be found in the following packages:\n($pkgs)"
)
}
)
}
}
}
```
### `command_not_found` Hook in _NixOS_
NixOS comes with the command `command-not-found`. We only need to plug it in the nushell hook:
```nu
$env.config.hooks.command_not_found = {
|command_name|
print (command-not-found $command_name | str trim)
}
```
### `command_not_found` Hook in _Windows_
The following hook uses the `ftype` command, to find program paths in _Windows_ that might be relevant to the user for `alias`-ing.
```nu
$env.config = {
...other config...
hooks: {
...other hooks...
command_not_found: {
|cmd_name| (
try {
let attrs = (
ftype | find $cmd_name | to text | lines | reduce -f [] { |line, acc|
$line | parse "{type}={path}" | append $acc
} | group-by path | transpose key value | each { |row|
{ path: $row.key, types: ($row.value | get type | str join ", ") }
}
)
let len = ($attrs | length)
if $len == 0 {
return null
} else {
return ($attrs | table --collapse)
}
}
)
}
}
}
```