Skip to content

Commit 38bd89b

Browse files
add Windows command_not_found example (#1576)
1 parent afc86c2 commit 38bd89b

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

book/hooks.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,3 +296,40 @@ $env.config = {
296296
}
297297
}
298298
```
299+
300+
301+
302+
### `command_not_found` Hook in _Windows_
303+
304+
The following hook uses the `ftype` command, to find program paths in _Windows_ that might be relevant to the user for `alias`-ing.
305+
306+
```nu
307+
$env.config = {
308+
...other config...
309+
310+
hooks: {
311+
...other hooks...
312+
313+
command_not_found: {
314+
|cmd_name| (
315+
try {
316+
let attrs = (
317+
ftype | find $cmd_name | to text | lines | reduce -f [] { |line, acc|
318+
$line | parse "{type}={path}" | append $acc
319+
} | group-by path | transpose key value | each { |row|
320+
{ path: $row.key, types: ($row.value | get type | str join ", ") }
321+
}
322+
)
323+
let len = ($attrs | length)
324+
325+
if $len == 0 {
326+
return null
327+
} else {
328+
return ($attrs | table --collapse)
329+
}
330+
}
331+
)
332+
}
333+
}
334+
}
335+
```

0 commit comments

Comments
 (0)